简体   繁体   中英

Is there a wildcard for elements in XMLSchema validation?

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>

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>

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM