Quite regularly I need to extract key value pairs from XML files. Is there an easy-to-use UNIX(-style) command line tool available for this?
Example case
The XML file looks like this:
<array>
<dict>
<key>BlackPointCompensation</key>
<false/>
<key>Name</key>
<string>Export A</string>
<key>WatermarkSettings</key>
<dict>
<key>DGOperationClassName</key>
<string>DGImageCompositeScaledOperation</string>
<key>inputKeys</key>
<dict>
<key>inputCompositeImagePath</key>
<string>/Users/me/imageA.psd</string>
<key>inputOpacity</key>
<real>0.94999999999999996</real>
</dict>
</dict>
</dict>
<dict>
<key>BlackPointCompensation</key>
<false/>
<key>Name</key>
<string>Export B</string>
<key>WatermarkSettings</key>
<dict>
<key>DGOperationClassName</key>
<string>DGImageCompositeScaledOperation</string>
<key>inputKeys</key>
<dict>
<key>inputCompositeImagePath</key>
<string>/Users/me/imageB.psd</string>
<key>inputOpacity</key>
<real>0.70</real>
</dict>
</dict>
</dict>
</array>
For this file I want to construct a command line command with the ("key" tag) parameter "inputCompositeImagePath"
which prints the ("string" tag) values /Users/me/imageA.psd
and /Users/me/imageB.psd
.
What's a good tool for this kind of operations? I had a brief look at xmllint
, but it doesn't seem to be well suited for this use case.