kamal
kamal

Reputation: 1193

Invalid content was found starting with element 'elementName'. No child element is expected at this point

I'm working with xml and I'm using xsd to validate my xml file. My xsd and xml file is too long and I can give you a part of them.

XSD file:

...
<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 file:

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

And the error was Reason: cvc-complex-type.2.4.d: Invalid content was found starting with element 'SWIFTBIC'. No child element is expected at this point. How can I solve it?

EDIT: I used xs:sequence before but the order of tags might be changeable that's why I couldnot use it. All elements can be occur, can be empty, can be doesn't occur..

Upvotes: 1

Views: 10962

Answers (2)

Erwin Bolwidt
Erwin Bolwidt

Reputation: 31269

Change complexType BankType into an xs:all instead of an xs:choice. But you can't have maxOccurs="unbounded" in an xs:all so you need to limit phone and fax numbers to max. 1 or you need to create a container element (PhoneNumbers etc.) that can contain multiple numbers but of which you can have a maximum of 1.

Upvotes: 0

Saurabh Sharma
Saurabh Sharma

Reputation: 509

As I can see in your xsd all elements are expected.

Choice Indicator

The indicator specifies that either one child element or another can occur:

Sequence Indicator

The indicator specifies that the child elements must appear in a specific order:

try this:-

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

Upvotes: 1

Related Questions