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