From: FX on
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?
From: bugbear on
FX wrote:
> I've a scenario where i need to parse all children with a name
> "interestingNodes" under a "Tree".

I think you mean "Descendants", not "children", in which case
getElementsByTagName does what you want, assuming your Node
is XML::DOM::Node

BugBear
From: Arne Vajhøj on
FX wrote:
> 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