Find elements based on xsd type with lxml

Posted by joet3ch on Stack Overflow See other posts from Stack Overflow or by joet3ch
Published on 2010-03-30T02:49:59Z Indexed on 2010/03/30 2:53 UTC
Read the original article Hit count: 355

Filed under:
|
|
|

I am trying to get a list of elements with a specific xsd type with lxml 2.x and I can't figure out how to traverse the xsd for specific types.

Example of schema:

<xsd:element name="ServerOwner" type="srvrs:string90" minOccurs="0">
<xsd:element name="HostName" type="srvrs:string35" minOccurs="0">

Example xml data:

<srvrs:ServerOwner>John Doe</srvrs:ServerOwner>
<srvrs:HostName>box01.example.com</srvrs:HostName>

The ideal function would look like:

    elements = getElems(xml_doc, 'string90')

    def getElems(xml_doc, xsd_type):
      ** xpath or something to find the elements and build a dict
      return elements

© Stack Overflow or respective owner

Related posts about python

Related posts about lxml