XPath语句不返回值,但为true或false

问题描述 投票:0回答:1

使用功能添加名称空间后:

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.js xml xpath opc-ua
1个回答
0
投票

您的XPath以= + 某字符串]结尾,因此只会返回truefalse

更改

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

to

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

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

© www.soinside.com 2019 - 2024. All rights reserved.