xml スキーマを使用して xml ファイル (ファイル "a") を検証する python スクリプトがあります。それはうまく機能し、元のxml(ファイル「a」)に別のxmlファイル(ファイル「b」)を含めたいと思います。問題は、含まれているファイル「b」を検証せずにファイル「a」を検証したいということです。
これは可能ですか?
Python コード:
from lxml import etree
xsd_doc=etree.parse('shiporder.xsd')
xsd = etree.XMLSchema(xsd_doc)
xml_file = etree.parse('file_a.xml')
xsd.validate(xml_file)
print(xsd.error_log)
XML スキーマ:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="file_input" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="xi:include" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
XML ファイル "a":
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2003/XInclude"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<file_input>
<xi:include href="shiporder2.xml" parse="xml"/>
</file_input>
<orderperson name=" John Smitha">John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>