[Jaxb]

Discussion in 'Java' started by Stefanie Ertheld, Jun 22, 2011.

  1. Hi,

    I've got an xml document like this:

    <xml version="1.0 encoding="UTF-8">
    <employees id="1" room="123">

    <employee>
    <firstname>Peter</firstname>
    <lastname>Meyer</lastname>
    </employee>
    <employee>
    <firstname>Betty</firstname>
    <lastname>Boo</lastname>
    </employee>

    </employees>

    How can that be mapped to jaxb annotations?
    I've tried all sorts of things, like:

    @XmlRootElement(name = "employees")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Employees {

    @XmlAttribute(name = "id")
    private String id;

    @XmlAttribute(name = "room")
    private String room;

    @XmlElement(name = "employee")
    @XmlElementWrapper(name = "employees")
    private Employee[] employees;
    [...]

    However, this doesn't work. There is a problem with the employees
    Element.
    On Google I found various examples of the type:

    <company>
    <employees id="1" room="123">

    <employee>
    <firstname>Peter</firstname>
    <lastname>Meyer</lastname>
    </employee>
    <employee>
    <firstname>Betty</firstname>
    <lastname>Boo</lastname>
    </employee>
    <employees>

    </company>

    This works easily - however when the document
    root element is also at the same time a list,
    I can't get it to work.
    Any ideas?

    Thanks in advance,

    Stefanie
    Stefanie Ertheld, Jun 22, 2011
    #1
    1. Advertising

  2. Stefanie Ertheld

    Stefan Ram Guest

    Stefanie Ertheld <> writes:
    >Subject: [Jaxb]


    Brackets usually are not used around the actual subject of a
    Usenet post.

    We might see some funny effects, when someone from certain
    web gateways responds to a post, where all of the subject is
    contained in brackets. (Well, in fact, the OP was posted via
    such a gateway.)
    Stefan Ram, Jun 22, 2011
    #2
    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. Sony Antony

    JAXB, XSLT comparison

    Sony Antony, Jul 17, 2003, in forum: Java
    Replies:
    1
    Views:
    916
    Arto V. Viitanen
    Jul 18, 2003
  2. Brahim Machkour

    JAXB and Arabic encoding

    Brahim Machkour, Jul 25, 2003, in forum: Java
    Replies:
    3
    Views:
    572
    Jon A. Cruz
    Jul 27, 2003
  3. Petterson Mikael

    XML to java using JAXB ?

    Petterson Mikael, Sep 2, 2003, in forum: Java
    Replies:
    0
    Views:
    398
    Petterson Mikael
    Sep 2, 2003
  4. Brett Selleck
    Replies:
    0
    Views:
    784
    Brett Selleck
    Sep 3, 2003
  5. Marcello Marangio

    JAXB generates incorrect xml content!!!

    Marcello Marangio, Oct 22, 2003, in forum: Java
    Replies:
    4
    Views:
    2,048
    Simon
    Oct 23, 2003
Loading...

Share This Page