相关疑难解决方法(0)

与元素内容无关的命名空间XPath查询

我见过的名称空间不可知语法令我困惑.

说我有:

<root>
  <parent attribute="A">A<child>A</child></parent>
  <parent attribute="B">B<child>B</child></parent>
</root>
Run Code Online (Sandbox Code Playgroud)

到目前为止,我看到如何:

/root/parent/child/text()
Run Code Online (Sandbox Code Playgroud)

翻译为:

/*[local-name()='root']/*[local-name()='parent']/*[local-name()='child']/text()
Run Code Online (Sandbox Code Playgroud)

但我正在努力做这样的事情:

/root/parent[@attribute="A"]/child/text()
Run Code Online (Sandbox Code Playgroud)

要么:

/root/parent[text()="B"]/child/text()
Run Code Online (Sandbox Code Playgroud)

要么:

/root/parent[1]/child/text()
Run Code Online (Sandbox Code Playgroud)

这些翻译怎么样?

谢谢,

编辑:再一次:-)

<root>
        <parent>
            <childName>serverName</childName>
            <childValue>MyServer</childValue>
        </parent>
        <parent>
            <childName>ServerLocation</childName>
            <childValue>Somewhere</childValue>
         </parent>
</root>
Run Code Online (Sandbox Code Playgroud)

这是如何翻译的?

/root/parent[childName="serverName"]/childValue/text()
Run Code Online (Sandbox Code Playgroud)

xpath default namespaces xml-namespaces

6
推荐指数
1
解决办法
6971
查看次数

标签 统计

default ×1

namespaces ×1

xml-namespaces ×1

xpath ×1