I have the following xml document (I have cleared out the irrelevant data):
<?xml version="1.0"?>
<NewOrderNotification xmlns="http://payments.amazon.com/checkout/2008-11-30/">
<ProcessedOrder>
<ShippingServiceLevel>blah</ShippingServiceLevel>
<ProcessedOrderItems>
<ProcessedOrderItem>
<AmazonOrderItemCode>blah</AmazonOrderItemCode>
<Price>
<Amount>0.2</Amount>
<CurrencyCode>GBP</CurrencyCode>
</Price>
<ItemCharges>
<Component>
<Type>Principal</Type>
<Charge>
<Amount>0.2</Amount>
<CurrencyCode>GBP</CurrencyCode>
</Charge>
</Component>
<Component>
<Type>Shipping</Type>
<Charge>
<Amount>0.95</Amount>
<CurrencyCode>GBP</CurrencyCode>
</Charge>
</Component>
<Component>
<Type>PrincipalPromo</Type>
<Charge>
<Amount>0.0</Amount>
<CurrencyCode>GBP</CurrencyCode>
</Charge>
</Component>
<Component>
<Type>ShippingPromo</Type>
<Charge>
<Amount>0.0</Amount>
<CurrencyCode>GBP</CurrencyCode>
</Charge>
</Component>
</ItemCharges>
<ShippingCustomData>null</ShippingCustomData>
</ProcessedOrderItem>
</ProcessedOrderItems>
</ProcessedOrder>
</NewOrderNotification>
I want to know the xpath syntax for getting each of the values within the 5 different <Amount> elements:
Namely how do I extract each of the following:
-
NewOrderNotification – ProcessedOrder – ProcessedOrderItems – ProcessedOrderItem – Price – Amount
-
NewOrderNotification – ProcessedOrder – ProcessedOrderItems – ProcessedOrderItem – ItemCharges – Component(with type=Principle) – Charge – Amount
-
NewOrderNotification – ProcessedOrder – ProcessedOrderItems – ProcessedOrderItem – ItemCharges – Component(with type=Shipping) – Charge – Amount
-
NewOrderNotification – ProcessedOrder – ProcessedOrderItems – ProcessedOrderItem – ItemCharges – Component(with type=PrincipalPromo) – Charge – Amount
-
NewOrderNotification – ProcessedOrder – ProcessedOrderItems – ProcessedOrderItem – ItemCharges – Component(with type=ShippingPromo) – Charge – Amount
Please note the xmlns in the root element.
This is the JScript code I’m using to extract elements:
var xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0");
xmlDoc.setProperty("SelectionNamespaces", "xmlns:a='http://payments.amazon.com/checkout/2008-11-30/'");
xmlDoc.loadXML(xml);
var node = xmlDoc.documentElement.selectSingleNode("XPATH_IN_HERE");
return node.text;
The first amount you can get with just:
For the other four, you can use the text of the preceding sibling
Typeelement to get their values:I think that does it. (Let me know if I misunderstood your question.)