exemplum
exemplum

Reputation: 115

JAXB annotation for childnode attribute

Lets say that i have following XML and i use JAXB for marshalling:

<bookstore name="bookstoreName">
    <book title="bookTitle">
         <author fullname="authorName">
         </author>
    </book>
</bookstore>

I know how to create:

I did this by using annotations @XmlRootElement, @XmlElement and @XmlAttribute.

What i don't know is how to create attributes of child nodes. For example attribute "title".

Upvotes: 1

Views: 700

Answers (1)

bdoughan
bdoughan

Reputation: 148977

title will be a property on the Book class annotated with @XmlAttribute. Book will be referenced by BookStore probably as a List property.

@XmlElement(name="book")
List<Book> getBooks() {
    return books;
}

Upvotes: 1

Related Questions