对具有任何命名空间前缀的属性进行 Xpath 表达式评估
Xpath Expression evaluation on attributes with any namespace prefix
你能帮我解决这个 xpath 表达式评估吗
我正在获取代理引用。在 xml 文件中,引用将存储为:
XML文件的一种方式参考如下:
con1:service ref="MyProject/ProxyServices/service1"
xsi:type="con2:PipelineRef" xmlns:ref="http://www.bea.com/wli/sb/reference"/
在 xml 文件中,名称 space 是:
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 文件中,名称 space 是:
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 文件中有多个引用时,名称 space 前缀会不断变化。
"//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 继续将名称 space 前缀从 con 更改为 con(n)。现在我正在寻找支持 @type='*:PipelineRef'
或 @type='con*:PipelineRef'
或获取服务元素引用属性值的最佳方式的东西。
提前致谢。
尝试像这样使用 contains()
:
//service[contains(@type,':ProxyRef') or contains(@type,':PipelineRef')]
另一种替代方法是使用 ends-with()
函数,与 contains()
函数相比,此函数更精确。但是,ends-with()
在 xpath 1.0 中不可用,因此您有可能需要 implement it yourself(可行,但 xpath 结果对我来说不太直观)。
你能帮我解决这个 xpath 表达式评估吗
我正在获取代理引用。在 xml 文件中,引用将存储为:
XML文件的一种方式参考如下:
con1:service ref="MyProject/ProxyServices/service1"
xsi:type="con2:PipelineRef" xmlns:ref="http://www.bea.com/wli/sb/reference"/
在 xml 文件中,名称 space 是:
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 文件中,名称 space 是:
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 文件中有多个引用时,名称 space 前缀会不断变化。
"//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 继续将名称 space 前缀从 con 更改为 con(n)。现在我正在寻找支持 @type='*:PipelineRef'
或 @type='con*:PipelineRef'
或获取服务元素引用属性值的最佳方式的东西。
提前致谢。
尝试像这样使用 contains()
:
//service[contains(@type,':ProxyRef') or contains(@type,':PipelineRef')]
另一种替代方法是使用 ends-with()
函数,与 contains()
函数相比,此函数更精确。但是,ends-with()
在 xpath 1.0 中不可用,因此您有可能需要 implement it yourself(可行,但 xpath 结果对我来说不太直观)。