Prev: LWUIT and J2ME
Next: in the Observer (Publish/Subscribe) pattern, are notifications alien method calls?
From: FX on 10 Sep 2009 08:33 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 10 Sep 2009 09:49 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 10 Sep 2009 17:31
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 |