Forum Stats

  • 3,874,309 Users
  • 2,266,718 Discussions
  • 7,911,811 Comments

Discussions

JAXB - setting multiple items

843834
843834 Member Posts: 49,972
edited Jul 14, 2001 8:03PM in Java Technology & XML
Hi there

I have generated a class that contains a list of items. And I noticed that the class that is generated, does not contains a setItem method at all. It has a getItem method ( List getItem() ) but no setItem. Any ideas why? And how can I solve this problem? Hope it isn't a bug in JAXB though.

I would really appreciate your help on this one.

Thanks
~Glen Verran

In the DTD the element was defined as follows:

<!ELEMENT Request ( Item*)>
<!ELEMENT Item ( Id, Name )>
<!ELEMENT Id (#PCDATA)>
<!ELEMENT Name (#PCDATA)>

My XJS File is defined as follows:

<xml-java-binding-schema version="1.0-ea">
<element name="Request" type="class" root="true"/>
<element name="Item" type="class" root="true"/>
</xml-java-binding-schema>

Comments

  • 843834
    843834 Member Posts: 49,972
    I think it is not a bug, it is a feature ! Why do you need a setter for a list ?
  • 843834
    843834 Member Posts: 49,972
    Use

    Request request = new Request();
    Item item = new Item();
    ...
    request.getItem().add(item);

    to add items to the list; an empty Item list (what's returned by getItem) is created when a Request is created.
    Hi there

    I have generated a class that contains a list of
    items. And I noticed that the class that is
    generated, does not contains a setItem method at all.
    It has a getItem method ( List getItem() ) but no
    setItem. Any ideas why? And how can I solve this
    problem? Hope it isn't a bug in JAXB though.

    I would really appreciate your help on this one.

    Thanks
    ~Glen Verran

    In the DTD the element was defined as follows:

    <!ELEMENT Request ( Item*)>
    <!ELEMENT Item ( Id, Name )>
    <!ELEMENT Id (#PCDATA)>
    <!ELEMENT Name (#PCDATA)>

    My XJS File is defined as follows:

    <xml-java-binding-schema version="1.0-ea">
    <element name="Request" type="class" root="true"/>
    <element name="Item" type="class" root="true"/>
    </xml-java-binding-schema>
This discussion has been closed.