node.js - XPath 语句不返回值,而是 true 或 false
问题描述
使用函数添加命名空间后:
var select = useNamespaces({ns1: "http://pippo.com/schema"})
我使用以下语句:
var Objects = select("//ns1:References/ns1:Reference[@ReferenceType="+typeofref+"]/text()="+id.toString(), ns);
我想要的输出是带有 ReferenceType = typeofref 和 text() = id 的所有引用
我得到的输出是:True
它似乎找到了一些东西,但它只是说有元素,但它没有检索它。有人知道为什么吗?
xm 文件是这个:
解决方案
您的 XPath 以=
+ some string 结尾,因此只会返回true
or false
。
改变
"//ns1:References/ns1:Reference[@ReferenceType="+typeofref+"]/text()="+id.toString()
至
"//ns1:References/ns1:Reference[@ReferenceType="+typeofref+" and .="+id.toString()+"]"
为了选择具有属性值和字符串值的所有ns1:References/ns1:Reference
元素。typeofref
@ReferenceType
id.toString()
推荐阅读
- javascript - 如何获取 Chrome 扩展程序以从 iframe 获取 Javascript 变量(dropzone)
- javascript - Kraken 交易所期货 API - 生成身份验证字符串 - 身份验证错误。Node.js
- system-verilog - const 对象句柄作为函数中的参数
- javascript - 输入带有电子邮件验证的输入,尝试清除错误消息并在单击复选框时使输入变灰
- regex - 如何在 awk 中生成错误消息列表?
- javascript - 在 reduce 函数中使用变量
- twitter-bootstrap - vb-tooltip 的自定义类
- linux-kernel - 如何在 Linux 中分配大的连续内存区域
- reactjs - 子路由不会在 SSR React App 上重新加载
- jquery - 没有从 jQuery 循环中获取值