Can anyone help me with this question?
Based on a result XML from a WebService (OBIEE) I generated an XSD in a online converter and with this XSD I generated the class mapped by means of the command xjc
.
javax.xml.bind.UnmarshalException: unexpected element (uri:"urn:schemas-microsoft-com:xml-analysis:rowset", local:"rowset"). Expected elements are <{}rowset>
This error was generated due to the presence of the xmlns
attribute in the first line of XML.
<rowset xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" >
I ended up solving this error by putting in all the annotations @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? Is there a way to define this namespace in a more general way?
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>
Generated XSD
<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>