Skip to main content

missing an @XmlRootElement on a XML substitutionGroup's

5 replies [Last post]
matthewleete
Offline
Joined: 2005-12-14

Hi

I have been creating some sample/prototype java code to create an xml file, using JAXB. I have done this with JAXBv1.0 and started to do the same with JAXBv2.0. Both are using the 'Sun' RI's.

I am using a set of Schema's from the AdsML consortium (www.adsml.org), this is an ecommercies standard for the Advertising Industry, it is creating a framework of schemas to allow B2B interactions.

My example is very basic (like my Java skills!) and based on the samples released with JAXB.

I am getting an error when I come to marshall the Jaxb object tree. The initial issue looks like a "missing an @XmlRootElement"

After a bit of investigation I have a couple of questions:

Does the v2.0 RI support substitutionGroup's currently?
The missing an @XmlRootElement on marshalling is for a element that is a substitution. The schema has a base element called 'Placement' and then a number of elements that substitute it and extend it i.e. "Placement.NewspaperMagazine" see below.

Does the v2.0 RI support JavaDoc currently?
I run the ant javadoc process and the doc files look incomplete and not completely structured.

I have edited the generated source to include the @XmlRootElement, and then it marshalls and produces an xml document but this invalid, the above substited element name is wrong!

If these are already reported errors please tell me the ref/link.

If you require more info, I am more that happy to provide details.

Thanks
Matthew

Infor:

Jaxb versions I am compiling with, using ant.

Java SDK build 1.5.0-b64
Jaxb v1.0, RI v1.0.5-b16-fcs - Working
Jaxb v2.0 RI v2.0-20051210-EA2

Extract from Schema

...
...

...
...

Sample Error

javax.xml.bind.MarshalException
- with linked exception:
[org.xml.sax.SAXException: unable to marshal type "org.adsml.adsmlbookings._1.Pl
acementNewspaperMagazine" as an element because it is missing an @XmlRootElement
annotation]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:266)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:200)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:70)
at Main.main(Main.java:264)
Caused by: org.xml.sax.SAXException: unable to marshal type "org.adsml.adsmlbook
ings._1.PlacementNewspaperMagazine" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:220)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:232)
at com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:80)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:99)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:251)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:591)
at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:29)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:132)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:99)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:251)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:505)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:241)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:454)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:263)
... 3 more

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rasinha_java
Offline
Joined: 2011-07-23
sekhar
Offline
Joined: 2003-06-25

Substitution groups is supported. Use the ObjectFactory method. See
http://forums.java.net/jive/thread.jspa?threadID=2043&messageID=30894#30894

matthewleete
Offline
Joined: 2005-12-14

Thanks for the link.

I read this, but I think I am already doing this.

//Now the placement object
PlacementNewspaperMagazine placeNews = objFactoryBok.createPlacementNewspaperMagazine();

I am using the Object Factories to create all objects.

Any other ideas?

Thanks
Matthew

matthewleete
Offline
Joined: 2005-12-14

Hi again

I have been looking at this, and I am starting to understand the use of JAXBElement and type substitution.

The problem is, I do not understand the syntax to use it.

Can anyone help, I have looked at the examples and can not find an example that does what I need to do.

Thanks
Matthew

yairzaslavsky
Offline
Joined: 2007-05-03

You can create your objects regulary without the factory.
For example, if the class of your desired object is X, simple use new X(); to create it.
then use the factory -

X x = new X();
JAXBElement xElement = factory.createX(x);

the factory has two methods of create for each type - one to create an object , and one to create a wrapping jaxb-element.

Then pass the xElement to the marshaller , for example:

myMarshaller.marshal(xElement,System.out);

this will print on the console the XML representation of X.
Hopes this helps anyone,

Yair