首页 > 解决方案 > 使用 Xpath1.0 提取操作名称

问题描述

我正在尝试从传入请求中提取操作名称。

要求:

<soapenv:Envelope xmlns:ser="http://visa.com/sd/pc/service" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
   </soapenv:Header>
   <soapenv:Body wsu:Id="id-058C2E38D966BC3F2E15372874505064" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <ser:ReportRequest FromDate="2017-11-01"  Timezone="GMT" ToDate="2017-11-30" TransactionType="All"/>
   </soapenv:Body>
</soapenv:Envelope>

使用的 Xpath/*[local-name()='Envelope']/*[local-name()='Body']/*

获取输出<ser:ReportRequest xmlns:ser="http://visa.com/sd/pc/service" FromDate="2017-11-01" Timezone="GMT" ToDate="2017-11-30" TransactionType="All"/>

预期输出ReportRequest

有什么建议吗?

标签: xpathxpath-1.0

解决方案


To retrieve the expected output ReportRequest you have to modify your XPath expression to

local-name(/*[local-name()='Envelope']/*[local-name()='Body']/*)

This gets the local-name of the first child in XPath-1.0.
If you'd want to get the names of all children you'd have to iterate over the core path expression and get the local-name() of each item separately.


If you'd have XPath-2.0 available, you could simplify that and use the following expression

/*[local-name()='Envelope']/*[local-name()='Body']/*/local-name()

to get all names of all the children of the soapenv:Body element.


推荐阅读