Did you look at the sample application and the API documentation? A quick
look at the header file for XPathEvaluator shows:
selectSingleNode()
selectNodeList()
evalute()
If you're sure your expression will select only one node, then use that.
Otherwise, if you're sure your expression evaluates to a node-set, use
selectNodeList(). Otherwise, you'll have to use evaluate and call
XObject::nodeset(). If the result of evaluating the expression is not, or
cannot be converted to a node-set(), you'll get an exception.
By the way, this line of your correct is incorrect if you wish to map
nodes:
XalanDocument* theDoc = theParserLiaison.createDocument(getDocument
(),false,true);
instead, do what the usage pattern does:
XalanDocument* theDoc = theParserLiaison.createDocument(getDocument());
This:
//How to get the xalanNode from the Evaluator
const XalanNode *xnode = (const XalanNode*)theResult.get();
is a recipe for disaster. Do yourself a favor and _never_ use C-style
casts ever again.
Dave
"Arigapudi,
Shyam" To:
"'[email protected]'" <[email protected]>
<Shyam.Arigapudi cc: (bcc: David N
Bertoni/Cambridge/IBM)
@ugs.com> Subject: selectSingleNode
03/15/2002 07:52
AM
Hi,
I already have a DomDocument from xerces.
I saw the stub about converting xalandocument to xerces and viceversa.
I am stuck at trying to convert the the XObjectPtr to a xalanNode. Then I
want
to map it back to Dom_node and go on.
Here is a simple function that I am trying to write and it does not work.
Could
someone help me out. Thanks.
DOM_Node aNode;
// Set up a XercesParserLiaison and use it to wrap the
DOM_Document
// in a XalanDocument.
XercesDOMSupport theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
XalanDocument* theDoc =
theParserLiaison.createDocument(getDocument(),false,true);
assert(theDoc);
XPathEvaluator theEvaluator;
// OK, let's find the context node...
XalanNode* const theContextNode =
theEvaluator.selectSingleNode(
theDOMSupport,theDoc,
XalanDOMString("/").c_str(),
theDoc->getDocumentElement());
if(theContextNode != 0)
{
// OK, let's evaluate the expression...
const XObjectPtr theResult(
theEvaluator.evaluate(
theDOMSupport,
theContextNode,
XalanDOMString(xpathExpr).c_str(),
theDoc->getDocumentElement()));
assert(theResult.null() == false);
const XercesDocumentBridge* bridge=
theParserLiaison.mapDocument(theDoc);
if(bridge)
{
//How to get the xalanNode from the
Evaluator
const XalanNode *xnode = (const
XalanNode*)theResult.get();
XalanDOMString str =
xnode->getNodeValue();
aNode = bridge->mapNode( xnode);
}
}
Regards,
Shyam Arigapudi
www.eds.com
[EMAIL PROTECTED]