This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

Unmarshalling of nested child elements using jaxb

Junliang Lim
Greenhorn

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.

<person>
<id>123</id>
<first-name>john</first-name>
<last-name>tan</last-name>
<phone-numbers total="1">
<phone-number>
<phone-type>mobile</phone-type>
<phone-number>12345678</phone-number>
</phone-number>
</phone-numbers>
<email-address>asd@gmail.com</email-address>
</person>







Thank you!
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

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


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
[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.
 
Don't get me started about those stupid light bulbs.
 
subject: Unmarshalling of nested child elements using jaxb
 
Similar Threads
JAXB Question
jaxb marshalling problem
JWSDP2.0 - problem in deploying hello-jaxws sample application
InvalidMappingException
Bean Creation Exception with Spring OXM and JAXB2