我有以下 xml 文档(我已经清除了不相关的数据):
<?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>
我想知道用于获取 5 个不同<Amount>
元素中的每个值的 xpath 语法:
即我如何提取以下各项:
NewOrderNotification - ProcessedOrder - ProcessedOrderItems - ProcessedOrderItem - 价格 - 金额
NewOrderNotification - ProcessedOrder - ProcessedOrderItems - ProcessedOrderItem - ItemCharges - 组件(类型=原则) - 费用 - 金额
NewOrderNotification - ProcessedOrder - ProcessedOrderItems - ProcessedOrderItem - ItemCharges - 组件(类型=Shipping) - 费用 - 金额
NewOrderNotification - ProcessedOrder - ProcessedOrderItems - ProcessedOrderItem - ItemCharges - 组件(类型=PrincipalPromo) - 费用 - 金额
NewOrderNotification - ProcessedOrder - ProcessedOrderItems - ProcessedOrderItem - ItemCharges - 组件(类型=ShippingPromo) - 费用 - 金额
请注意根元素中的 xmlns。
这是我用来提取元素的 JScript 代码:
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;