简体   繁体   中英

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>

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

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