Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem unmarshalling XML - file useing inheritance

843834May 14 2003 — edited May 15 2003
My application uses an xml - schema that describes a scene containing geometric objects. I use simple objects (sphere, box...) and complex objects (groups). every object is derived from the base type "node_type". I create Java-Files from this schema and this works fine. but when I try to unmarshal an xml file written according to the schema I receive an exception. It seems like the unmarshaller does not notice the "xsi:type" attribute. Everything works fine if I do not use inheritance.

Is there anything I do not see? Do I have to consider anything special if i want to use derived types in my xml file?

Thanks a lot,

Katja


// ------------ part of the xml schema i use -------- //
<xs:complexType name="group_type">
&nbsp;&nbsp; <xs:complexContent>
&nbsp;&nbsp;&nbsp;&nbsp; <xs:extension base="node_type">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <xs:sequence>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <xs:element name="child" type="node_type" minOccurs="0" maxOccurs="unbounded"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </xs:sequence>
&nbsp;&nbsp;&nbsp;&nbsp; </xs:extension>
&nbsp;&nbsp; </xs:complexContent>
</xs:complexType>

<xs:complexType name="sphere_type">
&nbsp;&nbsp; <xs:complexContent>
&nbsp;&nbsp;&nbsp;&nbsp; <xs:extension base="node_type">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <xs:sequence>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <xs:element name="radius" type="xs:float"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </xs:sequence>
&nbsp;&nbsp;&nbsp;&nbsp; </xs:extension>
&nbsp;&nbsp; </xs:complexContent>
</xs:complexType>


// ---------- the xml file i am trying to unmarshal -------- //

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited by Katja Hofmann -->
<xml_scene xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="geometry.xsd">
&nbsp;&nbsp; <xml_group> <!-- xml_group is of type group_type -->
&nbsp;&nbsp;&nbsp;&nbsp; <child xsi:type="sphere_type">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <radius>0.3</radius>
&nbsp;&nbsp;&nbsp;&nbsp; </child>
&nbsp;&nbsp; </xml_branch>
</xml_scene>


// ------------ the exception I get ----------------------- //

!! -- class javax.xml.bind.UnmarshalException was thrown during operation!
Unexpected element {}:height
javax.xml.bind.UnmarshalException: Unexpected element {}:height
&nbsp;&nbsp;&nbsp;&nbsp; at com.sun.xml.bind.unmarshaller.UnreportedException.createUnmarshalException(UnreportedException.java:59)
&nbsp;&nbsp;&nbsp;&nbsp; at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.reportAndThrow(SAXUnmarshallerHandlerImpl.java:406)
&nbsp;&nbsp;&nbsp;&nbsp; at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:96)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1488)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
&nbsp;&nbsp;&nbsp;&nbsp; at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:139)
&nbsp;&nbsp;&nbsp;&nbsp; at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:129)
&nbsp;&nbsp;&nbsp;&nbsp; at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:134)
&nbsp;&nbsp;&nbsp;&nbsp; at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:138)
&nbsp;&nbsp;&nbsp;&nbsp; at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:151)

... and so on ... :-(
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2003
Added on May 14 2003
7 comments
300 views