View Full Version : need something like getElementsByNodeName
I'm trying to get all the processing instructions up front so that I can process them prior to handling the XML document, but there doesn't seem to be a way to get them without traversing the entire document. I know how to do that, but I was hoping that there was already an elegant method to do so.
]|V|[agnus
12-09-2004, 06:37 PM
I don't understand... how does getElementsByTagName not achieve what you need?
Also, is this more of a JavaScript/DOM question?
getElementByTagName doesn't find processing instructions
so if you tried
document.getElementByTagName("mytarget") ;
it would not find
<?mytarget somedata ?>
mytarget is returned by Node.getNodeName(), but not Node.getTagName(),
at least, that's what seemed to happen when I tried it. I'll check again to make certain.
Alex Vincent
12-09-2004, 07:49 PM
If you're running on Mozilla or another modern platform (I don't know what Perl/PHP/friends support), try DOM 2 TreeWalker. It's exceedingly flexible. :cool:
I'm in java land so I'm using the org.w3c.dom classes
http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/traversal.html#Iterator-overview
and the Java bindings:
http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/java-binding.html
Keep in mind that this is still traversing the entire document. getElementsByTagName also traverses all children of the node it is called on, but it disguises that fact by giving you this nice magical method.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.