Search code examples
xmlxsdxml-namespacesxsd-validationxsd-1.1

<xs:openContent> causing error: 'invalid, misplaced, or occurs too often'


I am trying to figure out how to design my XSD to allow elements from any other namespace, and these other elements having elements from my namespace.

I learned from examples and discussions that <openContent> is the right thing to do so. But for some reasons, I don't get my schema valid. So I tried from scratch, based upon Example 12-40 Defining an interleaved open content model:

<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning">
    <xs:element name="product" type="OpenProductType" vc:minVersion="1.1" />
    <xs:complexType name="OpenProductType">
        <xs:openContent>
            <xs:any namespace="##other" processContents="lax" />
        </xs:openContent>
        <xs:sequence>
            <xs:element name="number" type="xs:integer" />
            <xs:element name="name" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

VSCode complains about line 6 (<xs:openContent>):

s4s-elt-invalid-content.1: The content of 'OpenProductType' is invalid. Element 'openContent' is invalid, misplaced, or occurs too often.

Why is this invalid?

Setting the XSD version to 1.1 did not solve this.

Changing the order of <xs:openContent> and <xs:sequence> has no effect either.


Solution

  • xs:openContent requires XSD 1.1

    Setting the XSD version to 1.1 did not solve this.

    Changing the version declaration in the XSD does not change the capabilities of the XSD processor you're using. The error you're receiving indicates that you're using an XSD 1.0 processor. Upgrade to a XSD 1.1 processor if you wish to use XSD 1.1 constructs such as xs:openContent.