Parsing XML from the command line

First apt-get install xmlstarlet. And let's say we have this XML file:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="">

We can use xmlstarlet sel to select elements. But first we need to tell it about the name space, so xmlstarlet sel -N x="".

Now let's use -t -v to start using some XPath. In our case /x:kml/x:Document/x:name. So in full xmlstarlet sel -N x="" -t -v "/x:kml/x:Document/x:name" the_xml_file.xml. This will print:

xml unix

Edit on github
comments powered by Disqus
Click me