I'm parsing an XML in python. I've an XSD schema to validate the XML. Can I get the type of a particular node of my XML as it was defined in XSD?
For example, my XML (small part) is
<deviceDescription>
<wakeupNote>
<lang xml:lang="ru">Русский</lang>
<lang xml:lang="en">English</lang>
</wakeupNote>
</deviceDescription>
My XSD is (once again a small part of it):
<xsd:element name="deviceDescription" type="zwv:deviceDescription" minOccurs="0"/>
<xsd:complexType name="deviceDescription">
<xsd:sequence>
<xsd:element name="wakeupNote" type="zwv:description" minOccurs="0">
<xsd:unique name="langDescrUnique">
<xsd:selector xpath="zwv:lang"/>
<xsd:field xpath="@xml:lang"/>
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="description">
<xsd:sequence>
<xsd:element name="lang" maxOccurs="unbounded">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute ref="xml:lang" use="required"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
During the parse I want to know that my tag wakeupNote is defined in XSD as complexType zwv:description. How to do this (in python)?
What do I need this for? Suppose I have a lot of these XMLs and I want to check that all of them have fields with English language filled. It would be easy to check that the <lang xml:lang="en"></lang>
is empty, but it is allowed not to specify this tag at all.
So the idea is to get all tags that may have language descriptions and check that <lang>
tag is present and has a non-empty content for en.
UPD
Since during validation my XML is checked against XSD, the validation engine knows types of all nodes. I had a similar question 7 month ago which is still with no answer. They are related, imho. Validating and filling default values in XML based on XSD in Python