Parsing XML Children

F

FX

I've a scenario where i need to parse all children with a name
"interestingNodes" under a "Tree".

<Tree>
<fruits>
<interestingNotes>....</interestingNotes>
<fruit>
<type>apple</type>
<interestingNotes>....</interestingNotes>
<vitamins>
....
<interestingNotes>....</interestingNotes>
<vitamins>
<fruit>
</fruits>
<interestingNotes>
<roots>.....</roots>
</Tree>

So here I want to extract all <interestingNotes> whether it's at
<tree>, <fruits> or <fruit> level.
I was trying this
NodeList fruits =
treeNode.getChildNodes();
Node n;
int j=0;
String nam;
for(; j<fruits.getLength();j++){
n = fr.item(j);
nam= n.getNodeName();
if (nam.startsWith("interestingNotes"))
break;
}
But this doesnt get all <interestingNotes> Is there a method of
getting all children?
 
A

Arne Vajhøj

FX said:
I've a scenario where i need to parse all children with a name
"interestingNodes" under a "Tree".

<Tree>
<fruits>
<interestingNotes>....</interestingNotes>
<fruit>
<type>apple</type>
<interestingNotes>....</interestingNotes>
<vitamins>
....
<interestingNotes>....</interestingNotes>
<vitamins>
<fruit>
</fruits>
<interestingNotes>
<roots>.....</roots>
</Tree>

So here I want to extract all <interestingNotes> whether it's at
<tree>, <fruits> or <fruit> level.
I was trying this
NodeList fruits =
treeNode.getChildNodes();
Node n;
int j=0;
String nam;
for(; j<fruits.getLength();j++){
n = fr.item(j);
nam= n.getNodeName();
if (nam.startsWith("interestingNotes"))
break;
}
But this doesnt get all <interestingNotes> Is there a method of
getting all children?

getElementsByTagName or XPath.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top