• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Document getChildren with TagName

 
Jonathan Bagshaw
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21002
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21002
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic