JAXB generates incorrect xml content!!!

M

Marcello Marangio

Hi all
I am using JAXB 1.0.1 (the one included in jwsdp 1.2) to marshal-unmarshal
xml content from a quite complex xml schema.
The problem is that the XML information I managed to generate is not
compliant to the schema the jaxb classes were generated from!!!
How is this possible?
Is there a limit in the schema's complexity that jaxb can handle?
Thanks
Marcello
 
M

Michael Borgwardt

Marcello said:
Hi all
I am using JAXB 1.0.1 (the one included in jwsdp 1.2) to marshal-unmarshal
xml content from a quite complex xml schema.
The problem is that the XML information I managed to generate is not
compliant to the schema the jaxb classes were generated from!!!
How is this possible?
Is there a limit in the schema's complexity that jaxb can handle?

May be a bug in JAXB, may be a restriction in JAXB (probably specific features,
rather than general complexity), may be an error in the schema itself.
We can't tell without seeing details.
 
M

Marcello Marangio

Michael Borgwardt said:
May be a bug in JAXB, may be a restriction in JAXB (probably specific features,
rather than general complexity), may be an error in the schema itself.
We can't tell without seeing details.
Right!
ok, details...
I tried to isolate the problem, and it looks like a parsing lack, due to the
particular type of language (LR2 ?) defined in my xml schema.

So, that's my schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Parent">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="Child1" type="xs:string"/>
<xs:element ref="Child2" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:element ref="Child2" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="Child2" type="xs:string"/>
</xs:schema>

I try to create the XML output:
<Parent >
<Child1>String</Child1>
<Child2>String</Child2>
<Child2>String</Child2>
</Parent>

That's the code:
....
ObjectFactory of = new ObjectFactory();
Parent p = of.createParent();
p.setChild1("child1 name1");
Child2 c2 = of.createChild2("Child2 1");
p.getChild2().add(c2);
Child2 c2_2 = of.createChild2("Child2 2");
p.getChild2().add(c2_2);
JAXBContext jc = JAXBContext.newInstance("myPackage");
Marshaller m = jc.createMarshaller();
m.marshal(p, System.out);
....

The exception is:

DefaultValidationEventHandler: [ERROR]: myPackage.impl.Child2Impl
Location: obj: myPackage.impl.ParentImpl@7
com.sun.xml.bind.serializer.AbortSerializationException:
myPackage.impl.Child2Impl
.....
.....
--------------- linked to ------------------

javax.xml.bind.MarshalException
- with linked exception:
[com.sun.xml.bind.serializer.AbortSerializationException:
myPackage.impl.Child2Impl]

I think the problem is that the parser cannot distinguish if a Child2
instance belongs to the first or to the second branch of the Parent
hierarchy in the schema.

Hope it helps to understand the problem, so you can help me :)

Ciao
Marcello
 
M

Michael Borgwardt

Marcello said:
I think the problem is that the parser cannot distinguish if a Child2
instance belongs to the first or to the second branch of the Parent
hierarchy in the schema.

Hope it helps to understand the problem, so you can help me :)

Sorry, I'm not that proficient with XML. If nobody can help you here,
try Sun's Java XML forum: http://forum.java.sun.com/forum.jsp?forum=34
 
S

Simon

Hi Marcello

If your having problems with JAXB, then try using Liquid technologies
XML Data binding wizard. The new version 3 beta now has excellent
support for XSD, and creates code for java, C++, VB6 & C#.

http://www.liquid-technologies.com/Scripts/DownloadBeta.asp

Cheers

Simon Sprott



Marcello Marangio said:
Michael Borgwardt said:
May be a bug in JAXB, may be a restriction in JAXB (probably specific features,
rather than general complexity), may be an error in the schema itself.
We can't tell without seeing details.
Right!
ok, details...
I tried to isolate the problem, and it looks like a parsing lack, due to the
particular type of language (LR2 ?) defined in my xml schema.

So, that's my schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Parent">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="Child1" type="xs:string"/>
<xs:element ref="Child2" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:element ref="Child2" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="Child2" type="xs:string"/>
</xs:schema>

I try to create the XML output:
<Parent >
<Child1>String</Child1>
<Child2>String</Child2>
<Child2>String</Child2>
</Parent>

That's the code:
...
ObjectFactory of = new ObjectFactory();
Parent p = of.createParent();
p.setChild1("child1 name1");
Child2 c2 = of.createChild2("Child2 1");
p.getChild2().add(c2);
Child2 c2_2 = of.createChild2("Child2 2");
p.getChild2().add(c2_2);
JAXBContext jc = JAXBContext.newInstance("myPackage");
Marshaller m = jc.createMarshaller();
m.marshal(p, System.out);
...

The exception is:

DefaultValidationEventHandler: [ERROR]: myPackage.impl.Child2Impl
Location: obj: myPackage.impl.ParentImpl@7
com.sun.xml.bind.serializer.AbortSerializationException:
myPackage.impl.Child2Impl
....
....
--------------- linked to ------------------

javax.xml.bind.MarshalException
- with linked exception:
[com.sun.xml.bind.serializer.AbortSerializationException:
myPackage.impl.Child2Impl]

I think the problem is that the parser cannot distinguish if a Child2
instance belongs to the first or to the second branch of the Parent
hierarchy in the schema.

Hope it helps to understand the problem, so you can help me :)

Ciao
Marcello
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top