XML 未知元素的架构验证

XML Schema Validation for unknown elements

我正在尝试使用 C# 中的架构验证 XML。我将在行元素下有一个未知元素。我正在使用 xs:any,出现以下错误

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

架构 -

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

您没有在 xs:anyand maxOccurs defaults to 1 上指定 maxOccurs,这意味着第二个元素 Name, 是不允许的,因此错误消息,

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

通过将 maxOccurs="unbounded" 添加到 xs:any 进行更正:

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