我们如何在节点retun(即(内检查值
飓风烧烤达令港
事实上,我不能用下面的代码选择撇号存在(//ns1:name[text((="飓风烧烤达令港"](。
正在获取错误消息: RuntimeException:net.sf.saxon.trans.XPathException:{…name〔text((=‘Hurricane’s Gr.…}中第2行的char 33处出现XPath语法错误:应为"]",找到名称"s">
我不能用下面的代码选择撇号存在(//ns1:name[text((="飓风烧烤达令港"](。
正在获取错误消息:运行时异常:net.sf.saxon.trans.XPathException:{…name[text((=‘Hurricane’s Gr.…}中第2行字符33处的XPath语法错误:应为"]",找到名称"s
在XPath2.0中,撇号或双引号可以通过将该字符加倍来转义。请参阅规则[75]和/76]here:http://www.w3.org/TR/xpath20/#terminal-符号
使用:
exists(//ns1:name[text()='Hurricane''s Grill Darling Harbour'])
基于XSLT 2.0的验证:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="ns1">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:sequence
select="exists(//ns1:name[text()='Hurricane''s Grill Darling Harbour'])"/>
</xsl:template>
</xsl:stylesheet>
当此转换应用于以下XML文档时:
<ns1:name xmlns:ns1="ns1">Hurricane's Grill Darling Harbour</ns1:name>
生成所需的正确结果:
true
如果您只能在XML文档中使用XPath 1.0表达式,并且字符串包含两种引号,请使用:
boolean(//ns1:name
[text()=concat('Hurricane "Mathew"', " strength's value")])
这是一个完整的基于XSLT1.0的验证:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="ns1">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select=
"boolean(//ns1:name
[text()=concat('Hurricane "Mathew"', " strength's value")])"/>
</xsl:template>
</xsl:stylesheet>
当此转换应用于以下XML文档时:
<ns1:name xmlns:ns1="ns1">Hurricane "Mathew" strength's value</ns1:name>
生成所需的正确结果:
true
Saxon开始支持7.0
版本中的一些XPath 2.0
请求。
SOAPUI版本5.1.2
使用Saxon9.1版本(新版本的撒克逊更改历史可以在此处查看(
然后,正如@DimitreNovatchev完美地解释的那样,在文本中为XPath 2.0
转义'
的一个可能选项是将符号加倍为''
:
exists(//ns1:name[text()='Hurricane''s Grill Darling Harbour'])
我只想增加另一种可能性;由于"
引号也是有效的,您可以用"
包装整个文本,并在其中使用'
。因此,在您的SOAPUIXPath match
断言中,您可以使用:
exists(//ns1:name[text()="Hurricane's Grill Darling Harbour"])
注意我是这样做的,因为我假设您必须在XPath查找节点文本时仅使用'
。如果你需要在用"
包装的文本中也使用"
,你必须像使用'
一样将"
加倍。
另外请注意,在SOAPUI中,可以使用*
作为名称空间的通配符,这样就可以减少表达式:
declare namespace ns='http://somenamespace/';
exists(//ns1:name[text()="Hurricane's Grill Darling Harbour"])
收件人:
exists(//*:name[text()="Hurricane's Grill Darling Harbour"])