|
next
|
 Subject: Need XPath to return just immediate child nodes Author: Jeff Michaels Date: 17 Apr 2007 04:18 PM
|
Hello,
Even though this is an XQuery forum, I believe XPath 2.o is a subset of XQuery, and so I will go ahead and ask this question...
I have been working feverishly to come up with an XPath expression that returns just 1-level deep of child nodes, and *no* grandchildren, along with those child nodes' attributes.
Assuming an XML fragment of:
<Products>
<Hardware location="" arrival="">
<Home location="" arrival="">
</Home>
<Business location="" arrival="">
</Business>
</Hardware>
<Software location="" arrival="">
<Home location="" arrival="">
</Home>
<Business location="" arrival="">
</Business>
</Software>
</Products>
I want to return those Product categories just under <Products> and to exclude <Products> element itself. Also, the child element names will not be known up front.
I only want to return something like:
<Hardware location="" arrival="">
</Hardware>
<Software location="" arrival="">
</Software>
The requirement is to not have any grandchild nodes and to include all child attributes...
If I execute an XPath expression of: //Products/* or //Products/child::node() or //Products/child::element(), I get child, grandchild, etc {a subtree}.
How do I get just the immediate children of a given node/element, along with it's attributes...?
Thanks,
Doogey
|
|
|