users@jaxb.java.net

Re: <xsd:extension> subclass elements do not get serialized on marshal

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 12:21:50 -0700

See https://jaxb.dev.java.net/guide/Unmarshalling_is_not_working__Help_.html

I think you are creating JAXBContext without adding the extended
Solution class.

Naveen Ravindra wrote:
> Hi Team,
> I m using <xsd:extension> in a xml schema file say xsd2 which
> extends an element of xsd1 and also adds few more attributes.
>
> when i marshal the root element of xsd1 and when i substitute subclass
> element of xsd2 extended incase of the element of xsd1, i will not be able
> to see the attributes added for the extended element in xsd2.
>
>
> xsd1
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:dp="http:///dp.ecore"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http:///dp.ecore">
> <xsd:complexType name="Test">
> <xsd:sequence>
> <xsd:element maxOccurs="1" minOccurs="1" name="solution"
> type="dp:Solution"/>
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:string"/>
> <xsd:attribute name="date" type="xsd:string"/>
> </xsd:complexType>
>
> <xsd:complexType name="Solution">
> <xsd:attribute name="Solutionid" type="xsd:string"/>
> </xsd:complexType>
>
> <xsd:element name="Solution" type="dp:Solution"/>
> <xsd:element name="Test" type="dp:Test"/>
> </xsd:schema>
>
> xsd2
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsd:schema xmlns:dcp="http://www.library.org" xmlns:dp="http:///dp.ecore"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.library.org">
> <xsd:import namespace="http:///dp.ecore" schemaLocation="xsd1.xsd" />
> <xsd:complexType name="Solution">
> <xsd:complexContent>
> <xsd:extension base="dp:Solution">
>
> <xsd:attribute name="solutionName" type="xsd:string" />
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
> <xsd:element name="Solution" type="dcp:Solution"></xsd:element>
>
> </xsd:schema>
>
>
>
> now when i marshal root element of xsd1 which is <Test> i need solution to
> have both the attributes
>
> Solutionid from xsd1 and solutionName from xsd2.
>
>
> Help at the earliest would be appreciated.
>
> Regards,
> Naveen Ravindra
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com