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 Reading Node from XML 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 "Reading Node from XML" Watch "Reading Node from XML" New topic

Reading Node from XML

sandeep lokhande
Ranch Hand

Joined: Jan 25, 2010
Posts: 118


My XML structure is as follows,

I want to extract and get all the values of "Field" from two different nodes InputRecord and OutputRecord,

The code for that which i have written is as,

How could i get separate values of InputRecord and OutputRecord ?

I want to use InputRecord values for some different purpose and OutputRecord for some different than that of InputRecord ,
here in this case i get all the values in the NodeList by,

Please suggest me if there is any option as such for separately getting these values.
thank you in advance.

Thanks and Regards,
Sandeep Lokhande.
Nick Oz

Joined: May 20, 2011
Posts: 2
You could either get the parent Node's name then add InputRecord and OutputRecord specific logic based on this value ...

or instead of going straight for Field you could retrieve InputRecord and OutputRecord separately then declare a new NodeList for Field. Naturally if you choose this option I would make this a function with the parent name as an argument (i.e. InputRecord).

Option 1 seems cleaner based on your example but I suppose depending on the size of the XML, number of parents (i.e. InputRecord) and the number of children each parent has it may make more sense to go directly to the parent.

Rob Spoor

Joined: Oct 27, 2005
Posts: 20269

Moving to our XML forum.

How To Ask Questions How To Answer Questions
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I would just use the two XPath expressions "/Connector/Interaction/InputRecord/Field" and "/Connector/Interaction/OutputRecord/Field".
sandeep lokhande
Ranch Hand

Joined: Jan 25, 2010
Posts: 118

thank you for your response, its helped me very much.
I agree. Here's the link:
subject: Reading Node from XML
It's not a secret anymore!