Dave, Many thanks for your comments. It was very useful for me. Now I could evaluate the expression //[EMAIL PROTECTED] = 'id1'] on a Xalan document, and got the desired value.
However, I am facing one issue with the expressions //[EMAIL PROTECTED] = 'ID1'] and id('ID1') in another case. These expressions I am applying on a Xerces document. (I parsed an XML using Xerces, converted the resultant xerces DOMDocument* to XalanDocument* using codes found in the archives, and applied the XPath evaluator). But these do not give me any value. Please note that the XML that was parsed with xerces, had one schema associated with it. In a nutshell, I'm able to run the expressions //[EMAIL PROTECTED] = 'ID1'] and id('ID1') on a XalanDocument* (after parsing an XML file by Xalan) with desired results, but not getting any values when run on a DOMDocument* (created by parsing an XML file using xerces). What needs to be done for the DOMDocument* case ? I need to do it as application stores data in xerces DOM. Regards, -Indrajit On Fri, 16 Feb 2007 David Bertoni wrote : >Indrajit Bhattacharya wrote: >>Dave, >> >>Now I'm doing the following (though its not working. pls. let me know how to >>proceed.):- >> >>The SimpleXPathAPI is evaluating by doing: >>XalanNode* const theContextNode = >> theEvaluator.selectSingleNode( >> theDOMSupport, >> theDocument, >> XalanDOMString(argv[2]).c_str(), >> thePrefixResolver); >>const XObjectPtr theResult( >> theEvaluator.evaluate( >> theDOMSupport, >> theContextNode, >> XalanDOMString(argv[3]).c_str(), >> thePrefixResolver)); theResult->str() returns the string >> id('id1'). >> >>I have added the following: >> >>string myStr; >>xalanc::XalanVector<char> data1; >>theResult->str().transcode(data1); >>myStr.assign(data1.begin(), data1.end()); >> >>const XObjectPtr theResult1( >> theEvaluator.evaluate( >> theDOMSupport, >> theContextNode, >> XalanDOMString(myStr.c_str()).c_str(), >> thePrefixResolver)); >>Here I'm passing the context node evaluated before along with the XPath >>expression got from the last evaluation. theResult1->str() is returning blank >>string here. > >It's probably because the id() function requires there be attributes of type >ID, which only happens if you validate the source document with a DTD or >schema that declares such attributes as type "ID." > >> >>Could you please tell me the correct way to proceed ? It would be very much >>helpful if you could provide some code snippet as I want to learn Xalan >>programming fast. > >Unless you can validate your source documents, I suggest you write some code >to pick out the ID value you're looking for, then use a simple XPath >expression to search for the element(s) you want. For example, you could >construct an XPath expression like this: > >//[EMAIL PROTECTED] = 'id1'] > >You could then evaluate that expression to find the element you're looking >forward. This is not nearly as efficient as the id() function, especially if >your documents are large. > >Dave