[XML-SIG] Does anyone do DOM navigation anymore?
Thomas B. Passin
tpassin at comcast.net
Tue Jul 6 06:04:26 CEST 2004
Derek Fountain wrote:
>>I use the DOM navigation all the time.
>>I do not know about XPATH so I cannot say if I would use that more than
> How do you cope with the fact that documents are to some extent unpredictable?
> Do you make heavy use of the methods/attributes which allow you to "feel
> around" to see what's coming (hasChildNodes, nodeType and so on)? Or do you
> only use DOM when you can be guaranteed about the structure of the document,
> and you therefore know that, for example,
> currentNode.firstChild.firstChild.lastChild.firstChild.nodeValue will give
> you text you're after?
I tend to use getElementsByTagName() and getElementById() as much as
possible. These, along with parentNode, help you avoid - well, OK,
reduce - that kind of dependence on precise structural details. Of
course, these are only useful if you know pretty well what you are
looking for. If you do, they reduce the fussiness.
In my own html/xhtml, I find that I also am helped by looking at the
values of class attributes. I would find it helpful if there were a
specific call (in the html dom, anyway), thisNode.getElementsByClassName().
> I'm starting to wonder if I've been doing the DOM right, as it were. It seems
> to me that when you don't know in advance how many children an element has,
> and you have to start feeling your way around, it makes the code rather
You especially want to avoid getting fooled by whitespace-only text
nodes and more generally, multiple PCData fragments.
Thomas B. Passin
Explorer's Guide to the Semantic Web (Manning Books)
More information about the XML-SIG