Shiju Samuel
Shiju Samuel

Reputation: 1591

XML Schema Validation for unknown elements

I am trying to validate the XML with the schema in C#. I will be having an unknown elements under the row element. I am using xs:any, I am getting the below error

The element 'row' has invalid child element 'Name'.

Schema -

<xs:element name="table">
  <xs:complexType>
    <xs:sequence>
      <xs:element maxOccurs="unbounded" name="row">
        <xs:complexType>
          <xs:sequence>
            <xs:any processContents="lax"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

XML -

<table>
  <row>
    <ProductID>994</ProductID>
    <Name>LL Bottom Bracket</Name>
    <ProductModel>LL Bottom Bracket</ProductModel>
    <CultureID>en    </CultureID>
    <Description>Chromoly steel.</Description>
  </row> 
</table>

Upvotes: 2

Views: 1264

Answers (1)

kjhughes
kjhughes

Reputation: 111491

You've not specified a maxOccurs on the xs:any, and maxOccurs defaults to 1, which means that the second element, Name, is not allowed, thus the error message,

The element 'row' has invalid child element 'Name'.

Correct by adding maxOccurs="unbounded" to xs:any:

        <xs:any processContents="lax" macOccurs="unbounded"/>

Upvotes: 3

Related Questions