Multiple XML Namespaces in tag with LXML

非 Y 不嫁゛ 提交于 2019-12-03 11:41:55

The problem is with your attribute name.

attrib={"{xsi}schemaLocation" : schemaLocation},

puts schemaLocation in the xsi namespace.

I think you meant

attrib={"{" + xsi + "}schemaLocation" : schemaLocation}

to use the URL for xsi. This matches your uses of namespace variables in the element name. It puts the attribute in the http://www.w3.org/2001/XMLSchema-instance namespace

That gives the result of

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     xmlns="http://www.topografix.com/GPX/1/1" 
     xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" 
     version="1.1" 
     creator="My Product"/>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!