Grovel. I appear to have sent this in HTML mail. Sorry.

-----Original Message-----
From: David J Craigon [mailto:david@;arabidopsis.info]
Sent: 31 October 2002 18:03
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: path searching in a DOM tree


Sounds like what you need is XPath, so what you need is Pathan (free), from
http://software.decisionsoft.com/. Unfortunately the latest stable version
(Pathan 1) only works with old style xerces-c (no pointers). If you're using
Xerces 2.1.0 (with pointers) (like me), you'll have to wait until their new
one comes out.

Alternatively, it's not so bad to do it with standard Xerces if you use a
DOMTreewalker . Suppose you've got a DOMDocument...


DOMNode *rootElem,*temp;
rootElem=doc->getDocumentElement();

walker=doc->createTreeWalker(rootElem,DOMNodeFilter::SHOW_ELEMENT,NULL,false
); // Just shows element nodes

temp=walker->firstChild();

while
(XMLString::compareString(temp->getNodeName(),XMLString::transcode("NODE1"))
!=0)
    temp=walker->nextSibling();

temp=walker->firstChild();

while
(XMLString::compareString(temp->getNodeName(),XMLString::transcode("NODE2"))
!=0)
    temp=walker->nextSibling();

temp=walker->firstChild();

while
(XMLString::compareString(temp->getNodeName(),XMLString::transcode("NODE3"))
!=0)
    temp=walker->nextSibling();

temp=walker->firstChild();

while
(XMLString::compareString(temp->getNodeName(),XMLString::transcode("NODE4"))
!=0)
    temp=walker->nextSibling();

// and you want temp->getNodeValue()

This assumes of course that all nodes exist. If they don't you will have to
check on the way down. Sorry if my (fairly bad) C++ isn't quite right- I'm
not as good as the regulars on this list!

    David
-----Original Message-----
From: Jason Jesso [mailto:jjesso@;global-matrix.com]
Sent: 31 October 2002 17:30
To: [EMAIL PROTECTED]
Subject: path searching in a DOM tree


Is there an easy way to search for a particular path in a DOM tree? Besides
doing a course on graph theory.
I want to search for something like:  /NODE1/NODE2/NODE3/NODE4  where the
name of NODE4 is XXX.
This path has several instances in the tree, but I want to find a particular
one.
--
<jason/>
--------------------------------------------------------------------- To
unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to