[xml] multiple XPath evaluations on the same document




I have a question regarding multiple XPath evaluations on the same document, specifically:
Assuming the base document is as follows:
<root>
  <parameter id="1"/>
  <parameter id="2"/>
  <element name="kid1">
     <parameter id="1"/>
  </element>
  <element name="kid2">
      <parameter id="1"/>
      <parameter id="2"/>
      <parameter id="3"/>
  </element>
</root>

I know I can retrieve all root::parameter nodes by allocating a new xpath context for the document and then evaluating the expression '/root/parameter'.

Let's say I traverse the document and am now at element with name="kid2", how do I use the same, already allocated xpath context to find all element::parameter nodes? Do I have to specify the element name attribute in the query ('/element[ name='kid2']/parameter')? Or is there a way for me to use the current 'element' node as the root for the next xpath query? (trying to avoid creating a new context for each of the queries on the same document)


Thanks very much.
Piotrek



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]