0

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.

Xstian
  • 8,184
  • 10
  • 42
  • 72
Sumit Kumar
  • 402
  • 1
  • 6
  • 26
  • Have you solved this problem? If you have solve it, How have you done? – Xstian Apr 15 '15 at 17:54
  • Yeah, i figured it out that my schema was wrong it had the element type but not the element itself, like in the first line of schema i did not have the ofx element earlier and the same was for other elements – Sumit Kumar Apr 16 '15 at 07:06
  • Perfect :) Could you add an answer to solve this topic? – Xstian Apr 16 '15 at 07:07

3 Answers3

1

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.

Natasha
  • 1,470
  • 5
  • 18
  • 24
1

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.

Sumit Kumar
  • 402
  • 1
  • 6
  • 26
0

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

Xstian
  • 8,184
  • 10
  • 42
  • 72