1

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>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Shiju Samuel
  • 1,373
  • 6
  • 22
  • 45

1 Answers1

2

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"/>
Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240