You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by AS...@desknetinc.com on 2002/08/05 22:44:23 UTC
Evaluating XPath expressions on a Xerces DOM
Hi all,
I am trying to write some software that will use Xalan to evaluate XPath
expressions, but my XML is represented in a Xerces DOM tree. It works
under some circumstances but not others; particularly, I am having trouble
constructing a mapping between Xalan nodes and Xerces nodes.
Here's a generalized snippet from my code:
doc is a DOM_Document, and xmlNode is a DOM_Node
// Set up a XercesParserLiaison and use it to wrap the DOM_Document
// in a XalanDocument.
XercesDOMSupport theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
XalanDocument* theDocument = theParserLiaison.createDocument(doc);
if (theDocument == NULL)
throw Exception("CannotCreateDocument");
XalanNode* theContextNode;
XercesDocumentBridge theBridge(doc);
XercesBridgeNavigator nav(&theBridge);
XPathEvaluator theEvaluator;
// OK, let's find the context node...
if (noContext)
{
theContextNode = theDocument->getDocumentElement();
}
else
{
theContextNode = nav.mapNode(xmlNode);
if (theContextNode == NULL)
throw Exception("InvalidContextNode");
}
If I haven't supplied a context node, it evaluates just fine (I'm passing
in one of the sample XPath expressions, and importing the foo.xml into a
Xerces DOM, and I get the expected result). However, if I try to supply
the root node (as a DOM_Node) of foo.xml as the context node, it throws the
Invalid Context Node expression. I've tried it just using
theBridge.mapNode(), and I also tried creating a navigator as you see here.
There doesn't seem to be much in the API docs to explain how these things
are all supposed to work, so I was hoping someone here had some experience
with this that they would like to share. Thanks!
______________________________________
Aaron Scifres
Software Engineer
DeskNet, Inc.
66 Pearl St. Suite 300
Portland, ME 04101
(207) 772-1484 x16
http://www.desknetinc.com
DeskNetAPS - Harness the Power of Your Content