发现以元素"elementName"开头的无效内容。此时不需要子元素



我正在使用XML,并且我正在使用XSD来验证XML文件。我的XSD和XML文件太长了,我可以给您其中的一部分。

XSD文件:

...
<xs:complexType name="BankType">
    <xs:choice>
        <xs:element name="Code" type="codeType" minOccurs="1" maxOccurs="1" />
        <xs:element name="NewCode" type="codeType" minOccurs="0" maxOccurs="1" />
        <xs:element name="SWIFTBIC" type="swiftType" minOccurs="0" maxOccurs="1" />
        <xs:element name="Name" type="nameType" minOccurs="0" maxOccurs="1" />
        <xs:element name="CorAccount" type="accountType" minOccurs="0" maxOccurs="1" />
        <xs:element name="SubCorAccount" type="accountType" minOccurs="0" maxOccurs="1" />
        <xs:element name="TaxNumber" type="taxNumberType" minOccurs="0" maxOccurs="1" />
        <xs:element name="Address" type="addressType" minOccurs="0" maxOccurs="1" />
        <xs:element name="PhoneNumber" type="phoneNoType" minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="FaxNumber" type="faxNumberType" minOccurs="0" maxOccurs="unbounded" />
    </xs:choice>
</xs:complexType>
<xs:complexType name="OperationsForBankType">
    <xs:sequence>
        <xs:element name="Method" type="methodType" minOccurs="1" maxOccurs="1" />
        <xs:element name="Bank" type="BankType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
</xs:complexType>
...

XML文件:

...
<Operations>
  <Method>ADD</Method>
  <Bank>
    <Code>111111</Code>
    <SWIFTBIC>AAAAAAAA</SWIFTBIC>
    <Name>ASDFGHJKL</Name>
    <CorAccount>1111111111111111111111111111</CorAccount>
    <SubCorAccount>1111111111111111111111111111</SubCorAccount>
    <TaxNumber>1700792251</TaxNumber>
    <Address>Bakı şəhəri, Nizami küçəsi, 70</Address>
    <PhoneNumber>+994125981107</PhoneNumber>
    <FaxNumber>+994125980307</FaxNumber>
  </Bank>
  ...

错误是Reason: cvc-complex-type.2.4.d: Invalid content was found starting with element 'SWIFTBIC'. No child element is expected at this point.我该如何解决?

编辑:我以前使用过xs:sequence,但是标签的顺序可能会更改,这就是为什么我无法使用它的原因。所有元素都可以发生,可以是空的,不会发生。

正如我在您的xsd中所看到的所有元素。

选择指示器

指示器指定可能发生一个子元素或另一个子元素:

序列指示器

指标指定子元素必须以特定顺序出现:

尝试以下操作: -

<xs:complexType name="BankType">
    <xs:sequence>
        <xs:element name="Code" type="codeType" minOccurs="1" maxOccurs="1" />
        <xs:element name="NewCode" type="codeType" minOccurs="0" maxOccurs="1" />
        <xs:element name="SWIFTBIC" type="swiftType" minOccurs="0" maxOccurs="1" />
        <xs:element name="Name" type="nameType" minOccurs="0" maxOccurs="1" />
        <xs:element name="CorAccount" type="accountType" minOccurs="0" maxOccurs="1" />
        <xs:element name="SubCorAccount" type="accountType" minOccurs="0" maxOccurs="1" />
        <xs:element name="TaxNumber" type="taxNumberType" minOccurs="0" maxOccurs="1" />
        <xs:element name="Address" type="addressType" minOccurs="0" maxOccurs="1" />
        <xs:element name="PhoneNumber" type="phoneNoType" minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="FaxNumber" type="faxNumberType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
</xs:complexType>

将复杂类型的bankType更改为 xs:all,而不是xs:选择。但是您不能在xs:all中拥有maxOccurs="unbounded",因此您需要将电话和传真号码限制在最大。1或您需要创建一个可以包含多个数字的容器元素(音核等)

最新更新