xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Etienne Roy <etienne....@ifrance.com>
Subject Re: Traversing a DOM by name
Date Tue, 09 Jan 2001 20:27:56 GMT
According to the Xerces 1.2.3 API, the method 'public NodeList
getElementsByTagName(java.lang.String name)' of the interface
org.w3c.dom.Element does exactly that. Is taht what you're looking for ?

Regards
Etienne

Simon Tyler wrote:

> Hi,
>
> I been trying to work out if there is an easy to traverse a DOM by element
> name. For example if I know the particular Node I am on has a child element
> called "childelement" then I would like to move directly to it. The only two
> ways I can see of doing this are either:
>
> 1. Iterate through the children using getFirstChild and getnextSibling
> checking the node name as I go. This is unsatifactory as I it would be nice
> to go directly to it in a "more efficient" manner.
>
> 2. Use getElementsByTagName. Unfortunately this returns all the Nodes for
> the whole tree below the current element when I am only interested in the
> immediate children.
>
> Is there an API kicking arounf that I haven't seen that lets me access
> elements by name just for immediate children. I know there are issues when
> more than one child exists with the name but in my case I know there will
> only ever be one.

You'll retreive a Nodelist, and you'll have to access the element via the item
method.



Mime
View raw message