为什么会出现XML错误cvc-complex-type.2.4.a: Invalid content was found starting with element 'Status'.应为“{FysiekeID}”之一

Why is the XML error occurringcvc-complex-type.2.4.a: Invalid content was found starting with element 'Status'. One of '{FysiekeID}' is expected

我有一个有 6 列的 table,我想为它创建一个 XML,当只有一个被填充时也是如此。

我通过填写所有 6 个文件创建了一个示例 XML;

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="AssetInterface">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="FysiekeID" type="xs:unsignedByte" nillable="true" minOccurs="1" />
        <xs:element name="BronID" type="xs:unsignedByte" nillable="true" minOccurs="1"  />
        <xs:element name="Bron" type="xs:string" nillable="true" minOccurs="1"/>
        <xs:element name="Status" type="xs:string" nillable="true" minOccurs="1"/>
        <xs:element name="Changed" type="xs:dateTime" nillable="true" minOccurs="1"/>
        <xs:element name="Created" type="xs:dateTime" nillable="true" minOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

有了这个,我得到了一个 XML 的完整填充对象;

<?xml version='1.0' encoding='utf-8'?>
<AssetInterface>
    <FysiekeID>1</FysiekeID>
    <BronID>1</BronID>
    <Bron>SAP</Bron>
    <Status>Synchronised</Status>
    <Changed>2021-10-08T04:41:23.617Z</Changed>
    <Created>2021-10-07T20:19:57.003Z</Created>
</AssetInterface>

但是当我想创建一个只包含状态字段的 XML 时,出现错误;

<?xml version='1.0' encoding='utf-8'?><AssetInterface><Status>_New</Status></AssetInterface>

Error occurred while parsing xml: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Status'. One of '{FysiekeID}' is expected.

我阅读了几个主题,认为 XSD 应该更改,添加了那些 nilleable 和 minoccurs 标签,但仍然没有区别。处理此消息的正确方法是什么?

如果您将 minOccurs="1" 更改为 minOccurs="0" ,它将使 XML 元素成为可选元素。