aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Reading Node from XML" Watch "Reading Node from XML" New topic
Author

Reading Node from XML

sandeep lokhande
Ranch Hand

Joined: Jan 25, 2010
Posts: 118

Hello,

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
Greenhorn

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.

-nick
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Moving to our XML forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

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.
 
Consider Paul's rocket mass heater.
 
subject: Reading Node from XML