I use the xjc tools to generate Java classes using the specified xsd schema
file.
and the Clause class has contents member and getter method(some other
methods are ignored here):
@XmlElements({
@XmlElement(name = "list", type = package.List.class),
@XmlElement(name = "table", type = Table.class),
@XmlElement(name = "graphic", type = Graphic.class),
@XmlElement(name = "paragraph", type = Paragraph.class),
@XmlElement(name = "link", type = Link.class)
})
protected java.util.List<Object> contents;
/**
* Gets the value of the contents property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the contents
property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getContents().add(newItem);
* </pre>
*
* <p>
* Objects of the following type(s) are allowed in the list
* {_at_link package.List }
* {_at_link Table }
* {_at_link Graphic }
* {_at_link Paragraph }
* {_at_link Link }
*
*/
public java.util.List<Object> getContents() {
if (contents == null) {
contents = new ArrayList<Object>();
}
return this.contents;
}
after I use the xml fragment and
Object obj = u.unmarshal(new File("E:/clause.xml"));
the obj is a Clause instance,and it's contents is null.
thanks for your help.
----- Original Message -----
From: "Jason Harrop" <jharrop_at_gmail.com>
To: <users_at_jaxb.dev.java.net>
Sent: Monday, April 28, 2008 2:27 PM
Subject: Re: [jaxb]can not generate right jaxb object
> What does it contain - presumably JAXBElement? If so, and its name is
> paragraph, use the getValue() method cast it to paragraph.
>
> On Mon, Apr 28, 2008 at 2:21 PM, zhangzhongliang
> <zhangzhongl_at_neusoft.com> wrote:
>>
>>
>> hi,
>>
>> I got a problem with generate jaxb object from a xml fragment.
>> The schema is like following:
>>
>>
>>
>> <xs:group name="contents">
>>
>> <xs:choice>
>>
>> <xs:element ref="graphic"/>
>>
>> <xs:element ref="table"/>
>>
>> <xs:element ref="list"/>
>>
>> <xs:element ref="link"/>
>>
>> <xs:element ref="paragraph"/>
>>
>> </xs:choice>
>>
>> </xs:group>
>>
>>
>>
>> <xs:element name="clause">
>>
>> <xs:complexType>
>>
>> <xs:sequence>
>>
>> <xs:element ref="paragraph"/>
>>
>> <xs:group ref="contents" minOccurs="0" maxOccurs="unbounded"/>
>>
>> <xs:element ref="sub_clause" minOccurs="0"
>> maxOccurs="unbounded"/>
>>
>> </xs:sequence>
>>
>> </xs:complexType>
>>
>> </xs:element>
>>
>> If I generate a Java Clause object with the following xml fragment:
>>
>> <clause id="ID_416303">
>>
>> <paragraph>paragraph1</paragraph>
>>
>> <paragraph>paragraph2</paragraph>
>>
>> <paragraph>paragraph3</paragraph>
>> </clause>
>>
>> the Clause.getContents() method return a List<Object> which does not
>> contain
>> any Paragraph instance.
>>
>> Anybody ever got this problem?
>>
>> thanks in advance.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>