我正在编写一个简单的 bash 脚本来解析一些 xml。我使用的是 sed 和 awk,但我认为 xmllint 更适合。
不幸的是,我对 xpath 完全陌生,所以我真的在战斗。
我正在尝试采用以下 xml:
<?xml version="1.0" encoding="UTF-8"?>
<releaseNote>
<name>APPLICATION_ercc2</name>
<change>
<date hour="11" day="10" second="21" year="2013" month="0" minute="47"/>
<submitter>Automatically Generated</submitter>
<description>ReleaseNote Created</description>
</change>
<change>
<version>2</version>
<date hour="11" day="10" second="25" year="2013" month="1" minute="47"/>
<submitter>fred.bloggs</submitter>
<description> first version</description>
<install/>
</change>
<change>
<version>3</version>
<date hour="12" day="10" second="34" year="2013" month="1" minute="2"/>
<submitter>fred.bloggs</submitter>
<description> tweaks</description>
<install/>
</change>
<change>
<version>4</version>
<date hour="15" day="10" second="52" year="2013" month="1" minute="38"/>
<submitter>fred.bloggs</submitter>
<description> fixed missing image, dummy user, etc</description>
<install/>
</change>
<change>
<version>5</version>
<date hour="17" day="10" second="31" year="2013" month="1" minute="40"/>
<submitter>fred.bloggs</submitter>
<description> fixed auth filter and added multi opco stuff</description>
<install/>
</change>
......
并处理它以将“3”作为变量传递给 xpath 脚本,并输出如下内容:
4 fred.bloggs 10/1/2013 15:38 fixed missing image, dummy user, etc
5 fred.bloggs 10/1/2013 17:40 fixed auth filter and added multi opco stuff
换句话说,每个节点的内容的复杂组合,其中版本的值大于例如3。