jQuery in Action, 2nd edition
The moose likes XML and Related Technologies and the fly likes DOM Parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "DOM Parsing" Watch "DOM Parsing" New topic
Author

DOM Parsing

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Hi
Is there any way using DOM API to find out how many occurences of a particular Node name are there in our XML
As I m trying to find a node having multiple occurences
but when i try to find it it stops after giving value of first node only


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
chris leonardi
Greenhorn

Joined: Feb 25, 2001
Posts: 3
Hi Gaurav -
This may not be the most elegant approach, but it should work:
Element root = doc.getDocumentElement();
NodeList nodes = root.getElementsByTagName("match");
int count = nodes.getLength();
One thing to keep in mind with this tactic is that it will match all matching descendents of the current element. For instance:
<a1>
<b1><match /></b1>
<b2><match /></b2>
<b3><match /></b3>
<b4>
<c1><match /></c2>
<c2><match /></c2>
<c3>
<d1><match /></d1>
<d2><match /></d2>
</c3>
</b4>
</a1>
This would find 7 nodes. Hope that helps.
Chris
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: DOM Parsing
 
Similar Threads
Write a Node object to a XML file
How get Node's ID from DOM?
Is there a listener
Searching XML elements using text and work with siblings
ParserImpl for DOM