· software-development xml

Parsing XML from the unix terminal/shell

I spent a bit of time today trying to put together a quick script which would allow me to grab story numbers from the commits in our Git repository and then work out which functional areas those stories were in by querying mingle.

Therefore I wanted to make a curl request to the mingle and then pipe that result somewhere and run an xpath expression to get my element.

I didn’t want to have to write code in another script file and then reference that file from the shell and in my search to achieve that I came across http://xmlstar.sourceforge.net/docs.php on stackoverflow.

It’s installable via mac ports:

sudo port install xmlstarlet

And I was then able to pipe the results of my mingle request and locate the following bit of XML:

<property type_description="Managed text list" hidden="false">
<name>Functional Area</name>
<value>Our Functional Area</value>
</property>
curl -s http://user:password@mingleurl:8888/api/v2/projects/project_name/cards/1.xml  | xmlstarlet sel -t -v "//property/name[. = 'Functional Area']/../value"

There’s much more you can do with the command which is listed on the documentation page.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket