File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Unmarshalling of nested child elements using jaxb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Unmarshalling of nested child elements using jaxb" Watch "Unmarshalling of nested child elements using jaxb" New topic

Unmarshalling of nested child elements using jaxb

Junliang Lim

Joined: Sep 22, 2012
Posts: 2
Can I ask regarding the java jaxb, if we have nested child elements in the xml document, how do we unmarshal it using java objects?

I am able to unmarshal all the single elements.
However for the nested child, I have difficulty unmarshalling the phone-type and phone-number in the PhoneNumber.class.

Attached are my files and the main method below to call the unmarshalling of xml.

<phone-numbers total="1">

Thank you!
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

Hi Junliang,
Questions regarding XML are better answered in our XML forum. I am moving this to the XML forum.

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 632
[0] You've decided to let go the attribute "total", that's fine as you like it to be.

[1] This is how you can rewrite your UserLinkedIn class taking into account of the wrapping element phone-numbers. The simplest way is to make it an inner class of UserLinkedIn so that the general layout will be preserve with minimum rewrite. This is how.

[2] Now the unmarshalling to verify everything is in place can look like this.
I agree. Here's the link:
subject: Unmarshalling of nested child elements using jaxb
jQuery in Action, 3rd edition