2
Я не могу разобрать свой xml-ответ.Ошибка при анализе ответа xml javax.xml.bind.UnmarshalException
Мой вопрос, что такое идеальный xsd, чтобы правильно разобрать ответ.
ОШИБКА:
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>
Мой XML-ответ:
<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>
XSD, что я сгенерировал из ответа выше в 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>
Благодаря Wanderson
Отлично! Ты босс! Как вы упомянули выше, мне просто нужно было удалить targetNamespace. Но имейте в виду, что если у вас есть пакет package-info.java в вашем пакете при генерации классов через JAXB, он будет помещать аннотацию туда, и вам также необходимо удалить его. ;) Блейз, Большое спасибо. –