给出docuent a.xml:
<?xml version="1.0"?>
<xml>
<listUsersResponse xmlns="http://www.algorithmics.com/schema">
<status>OK</status>
<users size="615">
<user>
<id>user1</id>
<name>Joe Doe</name>
<attributes size="0"/>
<status>ACTIVE</status>
<roleId>CREDIT_SUPPORT</roleId>
<password>454E454A77484D3566717547686858726842503755513D3D</password>
<timeout>0</timeout>
</user>
<user>
<id>user2</id>
<name>Tom Smith</name>
<attributes size="0"/>
<status>ACTIVE</status>
<roleId>RISK_MANAGEMENT</roleId>
<password>627678416458513567624E37384C314E626C30672B773D3D</password>
<timeout>0</timeout>
</user>
</users>
</listUsersResponse>
</xml>
我想提取<user>
节点的xml,该节点的id元素值为&#34; user1&#34;。
@skovorodkin :谢谢您的提示。现在我得到了节点。但它没有显示节点的全部内容:
$ xmllint --shell a.xml <<EOF
...setns x=http://www.algorithmics.com/schema
...xpath //x:users/x:user[x:id="user1"]
...EOF
/ > / > Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT user
我期待:
<user>
<id>user1</id>
<name>Joe Doe</name>
<attributes size="0"/>
<status>ACTIVE</status>
<roleId>CREDIT_SUPPORT</roleId>
<password>454E454A77484D3566717547686858726842503755513D3D</password>
<timeout>0</timeout>
</user>
答案 0 :(得分:2)
XPath正常工作并选择您要查找的元素。您在显示XPath表达式找到的节点时遇到问题。这取决于您用来处理XPath结果的应用程序或工具,而不是XPath本身。