我有以下XML。
<?xml version="1.0" encoding="UTF-8"?>
<Employees>
<Employee id="3">
<age>40</age>
<name>Tom</name>
<gender>Male</gender>
<role>Manager</role>
</Employee>
<Employee id="4">
<age>25</age>
<name>Meghna</name>
<gender>Female</gender>
<role>Manager</role>
</Employee>
</Employees>
我希望选择id为"4"的Employee元素。
我正在使用下面的XPath表达式,但没有返回任何内容。
//Employee/[@id='4']/text()
我在http://chris.photobooks.com/xml/default.htm上检查了一下,它显示无效的xpath,不确定问题出在哪里。
//
会选择和搜索文档中的 所有 节点,这可能会很慢。如果文档的结构已知,则应使用正确的路径,比如在 Gilles' 回答 中建议的那样。 - Jens