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 Sami Islam <sa...@detewe.de> on 2004/05/19 10:15:34 UTC
How to use Xpath from Xalan.
Hello,
I need some clarification on how to correctly use the XPathEvaluator in
Xalan.
In the sample programs from Xalan 1.7 the evaluator is first used :
1) to find the context node.
2) to find the list of nodes.
3) finally evaluate the result.
My questions:
1) Do I have to get a context node?
e.g. If I want the node at /doc/name[@first='Tom']/@last do I have to
first get the context node for "/" and then evaluate the expression
"doc/name[@first='Tom']/@last?
Isn't there a way I can just obtain the node directly without the 1)
step.
e.g. evaluator.selectSingleNode(..., ...,
XalanDOMString("/doc/name[@first='tom')/@last").c_str( ), ...); instead
of evaluator.selectSingleNode(..., ..., XalanDOMString("/").c_str( ),
...); first.
The only thing that is unclear to me is the evaluator.evaluate( ) member
function that takes a "context_node" as its second parameter and
"XpathString" as its third.
Regards,
Sami
Re: How to use Xpath from Xalan.
Posted by Francesc Guim Bernat <fg...@fib.upc.es>.
Sami Islam wrote:
> Hello,
> I need some clarification on how to correctly use the XPathEvaluator
> in Xalan.
>
> In the sample programs from Xalan 1.7 the evaluator is first used :
> 1) to find the context node.
> 2) to find the list of nodes.
> 3) finally evaluate the result.
>
> My questions:
> 1) Do I have to get a context node?
> e.g. If I want the node at /doc/name[@first='Tom']/@last do I have to
> first get the context node for "/" and then evaluate the expression
> "doc/name[@first='Tom']/@last?
>
> Isn't there a way I can just obtain the node directly without the 1)
> step.
> e.g. evaluator.selectSingleNode(..., ...,
> XalanDOMString("/doc/name[@first='tom')/@last").c_str( ), ...);
> instead of evaluator.selectSingleNode(..., ...,
> XalanDOMString("/").c_str( ), ...); first.
>
Sami,
You can use as a context node the documentElement node. For instance:
XalanElement* context = xalanDocument->getDocumentElement();
evaluator.selectSingleNode(domSupport, context,
XalanDOMString("/doc/name[@first='tom'])/@last").c_str( ), ...);
---------------------------------------
Francesc Guim Bernat
http://francesc.guim.net --
> The only thing that is unclear to me is the evaluator.evaluate( )
> member function that takes a "context_node" as its second parameter
> and "XpathString" as its third.
>
> Regards,
> Sami
>
RE: How to use Xpath from Xalan.
Posted by Erik Rydgren <er...@mandarinen.se>.
The document itself is a node. In your case the document is the context.
Just pass the address to the document as context.
/ Erik
-----Original Message-----
From: Sami Islam [mailto:sami.islam@detewe.de]
Sent: den 19 maj 2004 10:16
To: Xalan User List
Subject: How to use Xpath from Xalan.
Hello,
I need some clarification on how to correctly use the XPathEvaluator in
Xalan.
In the sample programs from Xalan 1.7 the evaluator is first used :
1) to find the context node.
2) to find the list of nodes.
3) finally evaluate the result.
My questions:
1) Do I have to get a context node?
e.g. If I want the node at /doc/name[@first='Tom']/@last do I have to
first get the context node for "/" and then evaluate the expression
"doc/name[@first='Tom']/@last?
Isn't there a way I can just obtain the node directly without the 1)
step.
e.g. evaluator.selectSingleNode(..., ...,
XalanDOMString("/doc/name[@first='tom')/@last").c_str( ), ...); instead
of evaluator.selectSingleNode(..., ..., XalanDOMString("/").c_str( ),
...); first.
The only thing that is unclear to me is the evaluator.evaluate( ) member
function that takes a "context_node" as its second parameter and
"XpathString" as its third.
Regards,
Sami