我正在解析Python中的XML。我有一個XSD模式來驗證XML。我可以如何在XSD中定義XML的特定節點的類型嗎?是否有可能獲得它在XSD中定義的XML節點的類型?
例如,我的XML(小部分)是
<deviceDescription>
<wakeupNote>
<lang xml:lang="ru">Русский</lang>
<lang xml:lang="en">English</lang>
</wakeupNote>
</deviceDescription>
我的XSD是(再一次的一小部分):
<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>
在解析我想知道我的標籤wakeup注在XSD中定義爲complexType zwv:說明。如何做到這一點(在Python中)?
我需要什麼?假設我有很多這些XML,並且我想檢查它們是否都有填充英文的字段。很容易檢查<lang xml:lang="en"></lang>
是否爲空,但是根本不允許指定該標籤。
這樣的想法是讓可能有語言描述的所有標記,並檢查<lang>
標籤存在並具有EN一個非空的內容。
UPD
由於驗證期間我的XML是對XSD檢查,確認引擎知道類型的所有節點。 7個月前我有類似的問題,但仍然沒有答案。他們是相關的,恕我直言。 Validating and filling default values in XML based on XSD in Python
我想找到XSD定義爲'zwv所有XML節點:在XSD description`,而不是所有的定義。舉例來說,在我的XSD我可以定義兩個`wakeupNote`:一個`內deviceDescription`爲`zwv:description`和彼此標籤爲'zwv內:shortdescription`。所以在我的XML中,我會有兩種`wakeupNote`。我只需要選擇那些類型爲「zwv:description」的人。怎麼做? – PoltoS 2011-02-03 08:58:01