xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Tyler" <tylersi...@hotmail.com>
Subject Re: Traversing a DOM by name
Date Tue, 09 Jan 2001 21:15:32 GMT

Unfortunately getElementsByTagName returns all the children which may the 
name in the sub-tree, not just those that match the name and are immediate 
children of the current node. I could use this but it would be doing a lot 
of extra work as it would traverse the whole sub-tree looking for elements 
that match and I only want to go down 1 level.


>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 ?
>Simon Tyler wrote:
> > Hi,
> >
> > I been trying to work out if there is an easy to traverse a DOM by 
> > name. For example if I know the particular Node I am on has a child 
> > called "childelement" then I would like to move directly to it. The only 
> > 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 
> > to go directly to it in a "more efficient" manner.
> >
> > 2. Use getElementsByTagName. Unfortunately this returns all the Nodes 
> > the whole tree below the current element when I am only interested in 
> > 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 
> > more than one child exists with the name but in my case I know there 
> > only ever be one.
>You'll retreive a Nodelist, and you'll have to access the element via the 
>In case of troubles, e-mail:     webmaster@xml.apache.org
>To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
>For additional commands, e-mail: general-help@xml.apache.org

Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

View raw message