users@jaxb.java.net

marshalling problem

From: Philip, Tim <Tim_Philip_at_intuit.com>
Date: Thu, 23 Oct 2003 11:17:58 -0700

I'm very confused. I'm probably doing something wrong, but this
seems really weird. I have a schema that supports this xml
document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a>
    <b>
                <c>
                        <data>foo</data>
                </c>
        </b>
</a>


Which works just fine when unmarshalling. It parses it just fine.
And I can marshall it back out and it looks the same. Great!

However ... if I construct the classes manually and unmarshall the
object tree I get this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a>
    <data>foo</data>
</a>

Which is completely invalid!! I certainly can't read it back in
without errors.

Here is the code I used to construct the object tree. I'm guessing
the problem is in here someplace. But I just don't see it.

    public static Object construct() throws JAXBException
    {
        ObjectFactory factory = new ObjectFactory();
        AElement a = factory.createAElement();
        BType b = factory.createBType();
        CType c = factory.createCType();

        a.getB().add(b);
        b.getC().add(c);
        c.setData("foo");

        return a;
    }

Here is the schema I used:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<xsd:schema
        elementFormDefault="qualified"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">

        <xsd:element name="a">
                <xsd:complexType>
                        <xsd:sequence maxOccurs="unbounded">
                                <xsd:element name="b" type="bType"
minOccurs="0"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>

        <xsd:complexType name="bType">
                <xsd:sequence maxOccurs="unbounded">
                        <xsd:element name="c" type="cType"/>
                </xsd:sequence>
        </xsd:complexType>

        <xsd:complexType name="cType">
                <xsd:sequence>
                        <xsd:element name="data" type="xsd:string"/>
                </xsd:sequence>
        </xsd:complexType>

</xsd:schema>


I'd greatly appreciate someone pointing out where exactly
I'm going wrong.


Thanks!
Tim.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net