Error when parsing xml response javax.xml.bind.UnmarshalException

I'm not being able to parse my xml response.

My question, what is the perfect xsd to parse the response correctly.

ERROR:

        javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"response"). 
    Expected elements are <{http://equityapi.morningstar.com/}Prices>,
<{http://equityapi.morningstar.com/}data>,<{http://equityapi.morningstar.com/}p>,
<{http://equityapi.morningstar.com/}response>

My xml response:

<response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<data idtype="ticker" id="FSRFX">
    <Prices>
        <p v="10.0" d="1986-09-29"/>
        <p v="88.63" d="2014-10-29"/>
    </Prices>
</data>

A xsd that I generated from the response above in XML Spy.

 <?xml version="1.0" encoding="UTF-8"?>
<!-- W3C Schema generated by XMLSpy v2015 sp1 (x64) (http://www.altova.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://equityapi.morningstar.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="p">
        <xs:complexType>
            <xs:attribute name="v" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="d" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:date">
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:element name="data">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="n1:Prices" xmlns:n1="http://equityapi.morningstar.com/"/>
            </xs:sequence>
            <xs:attribute name="idtype" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="id" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:element name="Prices">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="n1:p" maxOccurs="unbounded" xmlns:n1="http://equityapi.morningstar.com/"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="response">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="n1:data" xmlns:n1="http://equityapi.morningstar.com/"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Thanks Wanderson

Upvotes: 2

Views: 1353

Answers (1)

bdoughan
bdoughan

Reputation: 148977

Your XML response is not namespace qualified. If your XML is correct then you need to remove the targetNamespace from your XML schematic to reflect this.

Upvotes: 1

Related Questions