简体   繁体   中英

XSD: Content of an element does not matter

I am having some issues on achieving the following in my XSD Schema. I have an XML in which a data element is found. The content of this data element can vary depending on different transformations that take place. So I can't really put one schema on it.

I just want to ignore everything inside the data element, and let it just pass the schema without errors.

My XML:

<root>
    <element1>12345</element1>
    <element2>abcde</element2>
    <data>
        <lots></lots>
        <of></of>
        <content></content>
    </data>
</root>

In my XSD I do the following:

<xs:element name="data">
    <xs:complexType>
       <xs:sequence>
          <xs:any processContents="skip" minOccurs="0" />
       </xs:sequence>
     </xs:complexType>
</xs:element>

I thought of using processContents skip for this problem, but somehow, that doesn't work. Does anybody know why it doesn't work, or have a better solution at hand?

Thank you!

It should work. The problem in your example is that only one element is allowed inside <data> , since you didn't declare maxOccurs and the default is one . If you change it to

<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>

it should validate.

See fiddle .

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