Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JAXB generates incorrect xml content!!!

Reply
Thread Tools

JAXB generates incorrect xml content!!!

 
 
Marcello Marangio
Guest
Posts: n/a
 
      10-22-2003
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


 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-22-2003
Marcello Marangio wrote:
> 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.

 
Reply With Quote
 
 
 
 
Marcello Marangio
Guest
Posts: n/a
 
      10-22-2003

"Michael Borgwardt" <(E-Mail Removed)> ha scritto nel messaggio
news:bn5gnv$t5fui$(E-Mail Removed)-berlin.de...
> Marcello Marangio wrote:
> > 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.
>

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 xmlnss="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.AbortSerializationExce ption:
myPackage.impl.Child2Impl
.....
.....
--------------- linked to ------------------

javax.xml.bind.MarshalException
- with linked exception:
[com.sun.xml.bind.serializer.AbortSerializationExce ption:
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


 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-22-2003
Marcello Marangio wrote:

> 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

 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      10-23-2003
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/S...wnloadBeta.asp

Cheers

Simon Sprott



"Marcello Marangio" <(E-Mail Removed)> wrote in message news:<bn5puv$9o9$(E-Mail Removed)>...
> "Michael Borgwardt" <(E-Mail Removed)> ha scritto nel messaggio
> news:bn5gnv$t5fui$(E-Mail Removed)-berlin.de...
> > Marcello Marangio wrote:
> > > 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.
> >

> 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 xmlnss="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.AbortSerializationExce ption:
> myPackage.impl.Child2Impl
> ....
> ....
> --------------- linked to ------------------
>
> javax.xml.bind.MarshalException
> - with linked exception:
> [com.sun.xml.bind.serializer.AbortSerializationExce ption:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JAXB: Mapping XML to Existing Java Objects?? John Davison Java 3 07-26-2004 10:53 PM
Re: JAXB how to drop tag element in xml Enrique Java 0 04-01-2004 05:32 AM
JAXB javax.xml.bind.UnmarshalException Unexpected element Norberto Eichstaedt Java 0 01-17-2004 05:42 PM
Can JAXB be used to get a Java representation of an XML Schema? SOndei Java 0 01-15-2004 09:20 AM
XML to java using JAXB ? Petterson Mikael Java 0 09-02-2003 01:50 PM



Advertisments