Multiple XML Namespaces in tag with LXML

后端 未结 1 1425
自闭症患者
自闭症患者 2021-02-13 05:01

I am trying to use Pythons LXML library to create a GPX file that can be read by Garmin\'s Mapsource Product. The header on their GPX files looks like this



        
相关标签:
1条回答
  • 2021-02-13 05:45

    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"/>
    
    0 讨论(0)
提交回复
热议问题