【发布时间】:2011-06-24 14:35:36
【问题描述】:
我见过的与命名空间无关的语法让我感到困惑。
说我有:
<root>
<parent attribute="A">A<child>A</child></parent>
<parent attribute="B">B<child>B</child></parent>
</root>
到目前为止,我看到了:
/root/parent/child/text()
翻译为:
/*[local-name()='root']/*[local-name()='parent']/*[local-name()='child']/text()
但我正在为这样的事情苦苦挣扎:
/root/parent[@attribute="A"]/child/text()
或:
/root/parent[text()="B"]/child/text()
或:
/root/parent[1]/child/text()
这些如何翻译?
谢谢,
编辑:还有一个:-)
<root>
<parent>
<childName>serverName</childName>
<childValue>MyServer</childValue>
</parent>
<parent>
<childName>ServerLocation</childName>
<childValue>Somewhere</childValue>
</parent>
</root>
这是怎么翻译的?
/root/parent[childName="serverName"]/childValue/text()
【问题讨论】:
-
好问题,+1。有关所有提供的 XPath 表达式的建议、警告和完整翻译,请参阅我的答案。
标签: xpath namespaces default xml-namespaces