xml - parsing .xsd in python -


i need parse file .xsd in python parse xml.
using libxml2.
have parse xsd follow:

<xs:complextype name="classtype"> <xs:sequence>     <xs:element name="ieplcheader">         <xs:complextype>             <xs:sequence>                 <xs:element name="device-number" type="xs:integer" fixed="1"/>             </xs:sequence>             <xs:attribute name="version" type="xs:integer" use="required" fixed="0"/>         </xs:complextype>     </xs:element> 

when access with

doc.xpatheval('//xs:complextype/xs:sequence/xs:element[@name="ieplcheader"]'): 

tells me cannot find path.

while if remove xs: follow

<complextype name="classtype">   <sequence>     <element name="ieplcheader">         <complextype>             <sequence>                 <element name="device-number" type="xs:integer" fixed="1"/>             </sequence>             <attribute name="version" type="xs:integer" use="required" fixed="0"/>         </complextype>     </element> 

in way works

doc.xpatheval('//complextype/sequence/element[@name="ieplcheader"]'): 

does knows how can read of problem fixing prefix? righ preparsing file removing xs: it's orrible solution , hope able find better solution.

(i did not try py-dom-xpath yet , not know if may work xs:)

thanks, ste

if have deal xsd files, maybe using them validate xml files suggest pass lxml has support xmlschema files.

example code:

from lxml import etree cstringio import stringio  f = stringio()  f = stringio('''\  <xsd:schema xmlns:xsd="http://www.w3.org/2001/xmlschema">  <xsd:element name="a" type="atype"/>  <xsd:complextype name="atype">    <xsd:sequence>      <xsd:element name="b" type="xsd:string" />    </xsd:sequence>  </xsd:complextype>  </xsd:schema> ''')      xmlschema_doc = etree.parse(f)  xmlschema_doc.xpath('xsd:element',     namespaces={"xsd": "http://www.w3.org/2001/xmlschema"}) 

results in:

[<element {http://www.w3.org/2001/xmlschema}element @ 0x9a17f2c>] 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -