xpath - 使用 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
有什么建议吗?
解决方案
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.
推荐阅读
- python - pandas.read_csv() 不加载特殊字符
- java - 如何使用 JTextField、JButton 和 JLabel 构建带有图形区域paintComponent 的 JFrame 窗口?
- java - 我可以知道如何将uri转换为位图吗?
- c# - 检查字典中是否已经存在相同的对象
- php - woocommerce 自定义支付网关通过客户挂钩取消订单
- python-3.x - 升级到更强大的新笔记本电脑后,pymc3 运行非常缓慢
- bash - 尝试在 mac 上的 bash 脚本中运行 chrome 时出现问题
- r - 在分组数据中,如何仅按列的值排列 *some* 列的行,同时保持其余列不变?
- javascript - 为什么我尝试连接时无法访问 http 服务器
- c# - 运行读取时带有 IronOcr 的 PDF Ocr 抛出 SEHException