【问题标题】:XML Schema Validation for unknown elements未知元素的 XML 模式验证
【发布时间】:2015-12-14 06:15:59
【问题描述】:

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

元素“行”的子元素“名称”无效。

架构 -

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

【问题讨论】:

    标签: c# xml xsd xml-validation


    【解决方案1】:

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

    元素“行”的子元素“名称”无效。

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

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

    【讨论】:

      猜你喜欢
      • 2016-11-15
      • 1970-01-01
      • 2016-07-11
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多