|
next
|
Subject: XPath with the noprefix namespace Author: Neal Walters Date: 31 Jan 2006 05:20 PM
|
I'm trying to think through this, if I didn't have the no-namespace issue, my Xpath would simply be this:
/OrderPartitionResponse/Orders/Order[OrderPartitionStatusCode="InventoryExceptionsOnly"]
So this means select all "order" nodes where a child element has some specific value. I'm guessing Order is my "context node".
against this data:
<OrderPartitionResponse>
<Orders>
<Order>
<RequestDate>2006-01-10T13:15:00.0000000-07:00</RequestDate>
<OrderPartitionStatusCode>InventoryExceptionsOnly</OrderPartitionStatusCode>
</Order>
</Orders>
</OrderPartitionResponse>
The same data with the namespaces looks like this:
<OrderPartitionResponse xmlns="http://schemas.compassion.com/order/partitionresponse/2006-01-01">
<Orders>
<Order xmlns="http://schemas.compassion.com/order/2006-01-01">
<RequestDate>2006-01-10T13:15:00.0000000-07:00</RequestDate>
<OrderPartitionStatusCode>InventoryExceptionsOnly</OrderPartitionStatusCode>
</Order>
</Orders>
</OrderPartitionResponse>
If I just said /OrderPartitionResponse that is same as
/child::OrderPartitionResponse.
So could we walk through what this XPATH means?
/*[local-name()='OrderPartitionResponse']/*[local-name()='Orders'][1]/*[local-name()='Order'][1]/*[local-name()='OrderPartitionStatusCode'][. = 'InventoryExceptionsOnly']
When I run this, this selects the node that contains OrderPartitionStatusCode (including its value).
Since it starts with a /, that means start at the top of the document, then immediately I see *[xxx], so that means find all nodes where the thing in the brackets is true. Presumabley local-name() means find any element-name that matches the name of OrderPartitionResponse.
So I'm already confused where my axis and content node are.
As to the end, the [. = 'InventoryExceptionsOnly'] the "." means the context node, so it is selecting the context node where it's value is "InventoryExceptionsOnly". So that is why the OrderPartitionStatusCode is selected in the output.
Now, how do I select one node higher for the output, but still limit or filter based upon this type of criteria:
[OrderPartitionStatusCode="InventoryExceptionsOnly"]
Thanks again,
Neal
|
|
|