xml-xalan-c-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David N Bertoni/Cambridge/IBM" <david_n_bert...@us.ibm.com>
Subject Re: selectSingleNode
Date Fri, 15 Mar 2002 16:15:07 GMT

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:      "'xalan-c-users@xml.apache.org'" <xalan-c-users@xml.apache.org>
                          
                      <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
shyam@ugs.com







Mime
View raw message