我尝试使用 xmlstarlet 从以下示例 XML 中选择单个节点:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="key.xsl" ?>
<tables>
<tableset>
<table name="table1">
<row>
<fld name="fileName">
<strval><![CDATA[/my/XYZ/file1]]></strval>
</fld>
<fld name="fileName">
<strval><![CDATA[/my/XYZ/file2]]></strval>
</fld>
<fld name="fileName">
<strval><![CDATA[/my/other/XYZ/file3]]></strval>
</fld>
<fld name="worksBecauseUnique">
<strval><![CDATA[/XYZ/unique]]></strval>
</fld>
</row>
</table>
</tableset>
</tables>
Run Code Online (Sandbox Code Playgroud)
我正在尝试在 bash 中构建关联数组...如何选择单个节点,或使用 xmlstarlet 迭代多个节点?
到目前为止,我正在尝试类似以下的方法,但它不起作用:
xmlstarlet sel -t -v "//tables/tableset/table/row/fld[@name=\"fileName\"]/strval[0]" xmlfile.xml
Run Code Online (Sandbox Code Playgroud)
希望得到“/my/XYZ/file1”,但这不起作用。