3
Could someone help me with that question?
Based on a Webservice result XML (OBIEE) I generated an XSD in a online converter and with this XSD I managed the class mapped through the command xjc
.
When I tried to play the result in XML in the generated class (via JAXB unmarshaller) the following error occurred:
javax.xml.bind.UnmarshalException: unexpected element (uri:"urn:schemas-microsoft-com:xml-analysis:rowset", local:"rowset"). Expected elements are <{}rowset>
This error was generated by the presence of the attribute xmlns
in the first line of XML.
<rowset xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" >
I ended up solving this mistake by putting in all the notes @XmlElement
and @XmlType
the attribute namespace = "urn:schemas-microsoft-com:xml-analysis:rowset"
ex:
@XmlRootElement(name = "rowset", namespace = "urn:schemas-microsoft-com:xml-analysis:rowset" )
My question is: how to solve the problem without having to play namespaces in all these notes? There is a way to define this namespace more generally?
XML
<rowset xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" >
<Row>
<Column0>1337.0</Column0>
<Column1>TESTE1</Column1>
<Column2>2015-02-01T00:00:00</Column2>
<Column3>47367.0</Column3>
<Column4>129598.0</Column4>
<Column5>142231.0</Column5>
</Row>
<Row>
<Column0>1337.0</Column0>
<Column1>TESTE2</Column1>
<Column2>2015-03-01T00:00:00</Column2>
<Column3>224892.0</Column3>
<Column4>1624674.0</Column4>
<Column5>1289782.0</Column5>
</Row>
</rowset>
XSD Generated
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:schemas-microsoft-com:xml-analysis:rowset" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="rowset">
<xs:complexType>
<xs:sequence>
<xs:element name="Row" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="Column0"/>
<xs:element type="xs:string" name="Column1"/>
<xs:element type="xs:dateTime" name="Column2"/>
<xs:element type="xs:float" name="Column3"/>
<xs:element type="xs:float" name="Column4"/>
<xs:element type="xs:float" name="Column5"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Thank you very much, Anthony. !
– Paulo Gonçalo