[xml] Is it possible to do XPath queries in subtrees?
- From: Steinar Bang <sb dod no>
- To: xml gnome org
- Subject: [xml] Is it possible to do XPath queries in subtrees?
- Date: Fri, 28 Mar 2003 15:56:39 +0100
Since the only function that create an xmlXPathContext is
xmlPathNewContext() which takes xmlDoc argument, does this means that
it's only possible to do XPath queries from the top of documents?
What I would like to do, is to iterate over the list of customers in
the following fragment, and pick out the fields for each customer, as
efficiently as possible:
<customers>
<customer>
<id>1</id>
<name>A</name>
</customer>
<customer>
<id>2</id>
<name>B</name>
</customer>
</customer>
Asking for "//customer" gives me the list of customers, but where do I
go from there?
Is it safe to ask for "//id" and "//name" and then iterate over the
set of matches? Will the order be the same for the matches?
But what if a subelement is missing in one of the <customer>
elements...? Hm...
Is the best way to ask for "//customer" and then walk the tree
manually? Or is there an elegant XPath solution to this?
Thanx!
- Steinar
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]