My XML file consists of a general part, which I want to validate, and a special part, which is validated later (using a different xsd file which checks the general part again which is ok since it does not change).
How can I tell XMLSchema to check only for the element GeneralPart and not for the element SpecialPart? Also, the name SpecialPart should be interchangible if possible. So I'd like to replace <xs:element name="SpecialPart" minOccurs="0" maxOccurs="1">
with something like <xs:anything/>
...
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:element name="MyModule">
<xs:complexType>
<xs:sequence>
<!-- General part -->
<xs:element name="GeneralPart" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Version" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- Special part. -->
<xs:element name="SpecialPart" minOccurs="0" maxOccurs="1">
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
答案 0 :(得分:2)
There is an any
element:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:element name="MyModule">
<xs:complexType>
<xs:sequence>
<!-- General part -->
<xs:element name="GeneralPart" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Version" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:any minOccurs="0" maxOccurs="1" namespace="##any" processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
答案 1 :(得分:0)
Replacing <xs:element name="SpecialPart" minOccurs="0" maxOccurs="1">
with
<xs:element name="SpecialPart" type="xs:anyType" minOccurs="0" maxOccurs="1" />
works. However, I have to keep the name "SpecialPart".