JAXB generates incorrect xml content!!!

Discussion in 'Java' started by Marcello Marangio, Oct 22, 2003.

  1. 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
    Marcello Marangio, Oct 22, 2003
    #1
    1. Advertising

  2. 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.
    Michael Borgwardt, Oct 22, 2003
    #2
    1. Advertising

  3. "Michael Borgwardt" <> ha scritto nel messaggio
    news:bn5gnv$t5fui$-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 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
    Marcello Marangio, Oct 22, 2003
    #3
  4. 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
    Michael Borgwardt, Oct 22, 2003
    #4
  5. Marcello Marangio

    Simon Guest

    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" <> wrote in message news:<bn5puv$9o9$>...
    > "Michael Borgwardt" <> ha scritto nel messaggio
    > news:bn5gnv$t5fui$-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 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
    Simon, Oct 23, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Petterson Mikael

    XML to java using JAXB ?

    Petterson Mikael, Sep 2, 2003, in forum: Java
    Replies:
    0
    Views:
    391
    Petterson Mikael
    Sep 2, 2003
  2. hazz
    Replies:
    6
    Views:
    49,380
    SkyUCHC
    Jun 9, 2010
  3. Roedy Green
    Replies:
    1
    Views:
    318
  4. Berger, Daniel
    Replies:
    0
    Views:
    85
    Berger, Daniel
    Aug 17, 2006
  5. Replies:
    2
    Views:
    444
Loading...

Share This Page