我正在尝试使用XPath 1.0选择xml doc中具有特定命名模式属性的所有节点 .
示例XML:
<Foo>
<Bar id="1234">
<Attributes foo_attrib1="foo" foo_attrib2="bar"/>
</Bar>
<Bar id="2345">
<Attributes foo_attrib3="foobar"/>
</Bar>
<Bar id="3456"/>
</Foo>
我正在使用的查询是这样的:
/Foo/Bar/Attributes[starts-with(name(),'foo']
看起来这应该可行,但我没有得到任何返回此查询的节点 . 看起来这样也应该是一个非常简单的查询,所以我确定我只是弄乱了一些明显的东西 .
在此先感谢您的帮助!
2 回答
name()
返回您当前正在检查的节点的名称,在这种情况下是/ Foo / Bar / Attributes节点,因此name()
将返回"Attributes"
.你想看看/ Foo / Bar / Attributes的属性,所以你可能想要更像这样的东西:
因为
name()
指的是当前正在检查的节点的名称 .我不确定你是否可以匹配一个以......开头的属性