Sumit Kumar
Sumit Kumar

Reputation: 422

XML Validation: Invalid content was found starting with element

I am facing this problem and not able o resolve it. I have this xsd OFX.xsd. The xml i want to validate with this schema is following

<?xml version="1.0"?>
<OFX>
    <SIGNONMSGSRSV1>
        <SONRS>
            <STATUS>
                <CODE>0</CODE>
                <SEVERITY>INFO</SEVERITY>
            </STATUS>
            <DTSERVER>20120716233626.570[-7:PDT]</DTSERVER>
            <LANGUAGE>ENG</LANGUAGE>
            <FI>
                <ORG>Symitar</ORG>
                <FID>01182</FID>
            </FI>
            <INTU.BID>01182</INTU.BID>
            <INTU.USERID>66983</INTU.USERID>
        </SONRS>
    </SIGNONMSGSRSV1>
    <BANKMSGSRSV1>
        <STMTTRNRS>
            <TRNUID>0</TRNUID>
            <STATUS>
                <CODE>0</CODE>
                <SEVERITY>INFO</SEVERITY>
            </STATUS>
            <STMTRS>
                <CURDEF>USD</CURDEF>
                <BANKACCTFROM>
                    <BANKID>
                    </BANKID>
                    <ACCTID>66983-S80</ACCTID>
                    <ACCTTYPE>CHECKING</ACCTTYPE>
                </BANKACCTFROM>
                <BANKTRANLIST>
                    <DTSTART>20120501</DTSTART>
                    <DTEND>20120716</DTEND>
                    <STMTTRN>
                        <TRNTYPE>FEE</TRNTYPE>
                        <DTPOSTED>20120713135400</DTPOSTED>
                        <TRNAMT>-25.00</TRNAMT>
                        <FITID>30403620120713WF</FITID>
                        <NAME>Account Transaction</NAME>
                        <MEMO>Withdrawal Fee</MEMO>
                    </STMTTRN>
                </BANKTRANLIST>
                <LEDGERBAL>
                    <BALAMT>-254.64</BALAMT>
                    <DTASOF>20120716233626</DTASOF>
                </LEDGERBAL>
                <AVAILBAL>
                    <BALAMT>-254.64</BALAMT>
                    <DTASOF>20120716233626</DTASOF>
                </AVAILBAL>
            </STMTRS>
        </STMTTRNRS>
    </BANKMSGSRSV1>
</OFX>

And when i tried to validate this xml online or with java code. I am getting following errors.

cvc-complex-type.2.4.d: Invalid content was found starting with element 'SEVERITY'
cvc-complex-type.2.4.d: Invalid content was found starting with element 'DTSERVER'
cvc-complex-type.2.4.d: Invalid content was found starting with element 'FID'
and so on....

Suggest me what is the mistake in xsd.

Upvotes: 0

Views: 1602

Answers (3)

Sumit Kumar
Sumit Kumar

Reputation: 422

As I mentioned in the comment. The problem was with the schema, it has element type defined but nowhere the element is mentioned in the schema so the parser was throwing the error of invalid content.

Upvotes: 1

Natasha
Natasha

Reputation: 1480

You have choice for several types

<xs:complexType name="SONRS">
        <xs:choice>
            <xs:element name="STATUS" type="STATUS" minOccurs="0"
                maxOccurs="1" />
            <xs:element name="DTSERVER" type="xs:string" minOccurs="0"
                maxOccurs="1" />
            <xs:element name="LANGUAGE" type="xs:string" minOccurs="0"
                maxOccurs="1" />
            <xs:element name="DTPROFUP" type="xs:string" minOccurs="1"
                maxOccurs="1" />
            <xs:element name="DTACCTUP" type="xs:string" minOccurs="0"
                maxOccurs="1" />
            <xs:element name="FI" type="FI" minOccurs="0" maxOccurs="1" />
        </xs:choice>
    </xs:complexType>

Same goes for STATUS. So you should include only one of the elements in xml for SONRS , and if you include STATUS you have :

<xs:complexType name="STATUS">
        <xs:choice>
            <xs:element name="CODE" type="xs:integer" minOccurs="0"
                maxOccurs="1" />
            <xs:element name="SEVERITY" type="xs:string" minOccurs="0"
                maxOccurs="1" />
            <xs:element name="MESSAGE" type="xs:string" minOccurs="0"
                maxOccurs="1" />
        </xs:choice>
    </xs:complexType>

so you should include CODE or SEVERITY or MESSAGE.

Upvotes: 1

Xstian
Xstian

Reputation: 8272

You have declared every things like <xs:choice>

    <xs:complexType name="STATUS">
        <xs:choice>
            <xs:element name="CODE" type="xs:integer" minOccurs="0" maxOccurs="1"/>
            <xs:element name="SEVERITY" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="MESSAGE" type="xs:string" minOccurs="0" maxOccurs="1"/>
        </xs:choice>
    </xs:complexType>

change it in <xs:sequence> or <xs:all>

   <xs:complexType name="STATUS">
        <xs:sequence>
            <xs:element name="CODE" type="xs:integer" minOccurs="0" maxOccurs="1"/>
            <xs:element name="SEVERITY" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="MESSAGE" type="xs:string" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

Choice reference here XML Schema choice element allows only one of the elements contained in the declaration to be present within the containing element.

XSD Indicators reference

Upvotes: 0

Related Questions