aspose file tools*
The moose likes XML and Related Technologies and the fly likes Document getChildren with TagName Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Document getChildren with TagName" Watch "Document getChildren with TagName" New topic
Author

Document getChildren with TagName

Jonathan Bagshaw
Greenhorn

Joined: May 05, 2006
Posts: 14
What's a good way to get all the immediate Child nodes in a org.w3c.dom.Document with a particular TagName?

getElementsByTagNameNS (String namespaceURI, String localName) looks promising, but I can't figure out how the parameters work.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

The first parameter is the namespace URI of the element name (not the prefix, the URI the prefix is mapped to via xmlns:prefix). The second parameter is the local part of the element name (i.e. excluding the prefix).

I assume you are asking because you're looking for a namespaced element name. If there are no namespaces involved then I think you'll find there is a similar method named getElementsByTagName.
Jonathan Bagshaw
Greenhorn

Joined: May 05, 2006
Posts: 14
No.. I don't have any namespaces.. At least nothing specifically specified.
I was looking at getElementsByTagNameNS because the problem with getElementsByTagName is that it gets ALL child nodes with a particular name..

Whereas, I'm trying to ensure that I only grab the immediate children with a given name.
[ March 23, 2007: Message edited by: Jonathan Bagshaw ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Ah. Then you'll have to write the loop yourself. The only difference between getElementsByTagName and getElementsByTagNameNS is that the latter is namespace-aware.

Or you could use XPath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Document getChildren with TagName