首页 > 解决方案 > 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 文件是这个:

https://raw.githubusercontent.com/OPCFoundation/UA-Nodeset/master/Robotics/Opc.Ua.Robotics.NodeSet2.xml

标签: node.jsxmlxpathopc-ua

解决方案


您的 XPath 以=+ some string 结尾,因此只会返回trueor false

改变

"//ns1:References/ns1:Reference[@ReferenceType="+typeofref+"]/text()="+id.toString()

"//ns1:References/ns1:Reference[@ReferenceType="+typeofref+" and .="+id.toString()+"]"

为了选择具有属性值和字符串值的所有ns1:References/ns1:Reference元素。typeofref@ReferenceTypeid.toString()


推荐阅读