您能帮我做一下xpath表达式的计算吗?
我正在努力获取代理引用。在xml文件中,引用将存储为:
XML文件的一种方式将具有如下引用:
con1:service ref="MyProject/ProxyServices/service1"
xsi:type="con2:PipelineRef" xmlns:ref="http://www.bea.com/wli/sb/reference"/在xml文件中,名称空间如下:
xmlns:con1="http://www.bea.com/wli/sb/stages/config"
xmlns:con2="http://www.bea.com/wli/sb/pipeline/config"另一种XML方式将具有以下引用。
con1:service ref="MyProject/ProxyServices/service2"
xsi:type="ref:ProxyRef" xmlns:ref="http://www.bea.com/wli/sb/reference"/在xml文件中,名称空间如下:
xmlns:con1="http://www.bea.com/wli/sb/stages/config"
xmlns:ref="http://www.bea.com/wli/sb/reference"我已经使用了这个xpath表达式,这不是获取引用服务值,请您帮助它中的错误。
"//service[@type= @*[local-name() ='ProxyRef' or @type=@*[local-name() ='PipelineRef']]/@ref"当我像这样使用时,它是工作的,但是,当xml文件中有多个引用时,名称空间前缀会保持不变。
"//service[@type='ref:ProxyRef'or @type='con:PipelineRef' or @type='con1:PipelineRef' or @type='con2:PipelineRef' or @type='con3:PipelineRef' ...@type='con20:PipelineRef' ]/@ref"; 现在,基本上,类型属性PipelineRef将名称空间前缀从con更改为con(n)。现在,我正在寻找一些支持某些东西的东西,比如@type='*:PipelineRef'或@type='con*:PipelineRef',或者获取服务元素引用属性值的最佳方法。
提前谢谢。
发布于 2015-05-18 08:51:07
尝试像这样使用contains():
//service[contains(@type,':ProxyRef') or contains(@type,':PipelineRef')]另一种选择是使用ends-with()函数,与contains()函数相比,它在这方面更为精确。但是,ends-with()在XPath1.0中是不可用的,所以您有可能需要implement it yourself (可行,但对我来说,这个结果不那么直观)。
https://stackoverflow.com/questions/30298127
复制相似问题