像这样跑步时
$ xmlstarlet sel -t -v '//department[@id="123879"]/user/@name' -n file.xml
它只返回第一个用户的名字T:106603
和一个空行。
以下是名为 file.xml 的文件中的相关XML代码(用于测试目的):
<config name="department" version="1.11">
<xad version="1459" nocheckoutver="1701">
<!-- ... -->
<department name="/fighters" id="123879" group="channel" case="none" use="no">
<replication region="4334">
<options index_name="index.html" listing="0" sum="no" allowed="no" />
<!-- ... -->
</replication>
<target prefix="http" suffix=".net" />
<!-- ... -->
<user name="T:106603" />
<user name="T:123879" />
<user name="test" />
<user name="ele::123456" />
<user name="company-temp" />
<user name="companymw2" />
<user name="bird" />
<user name="coding11" />
<user name="plazamedia" />
<allow go="123456=abcdefghijklmnopqrstuvwxyz" />
<!-- ... -->
</department>
<department name="/dancers" id="876543" group="floor" case="yes" use="no">
<!-- ... -->
</department>
<!-- ... -->
</xad>
</config>