title: Native shell command set to extract node value from XML
body: <p>I'm trying to extract the value of a node from a pom.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.me.labs&lt;/groupId&gt;
          &lt;artifactId&gt;my-random-project&lt;/artifactId&gt;
          &lt;version&gt;1.5.0&lt;/version&gt;
      &lt;/parent&gt;
      ...
  &lt;/project&gt;
  </code></pre>
  
  <p>I need to extract the artifactId and version from the XML using a shell command. I have the following requirements/observations:</p>
  
  <ol>
  <li>The shell script will be done within a build assembly file we use at work, so the smaller the script the better.</li>
  <li>Since it'll be used on multiple systems (usually RHEL5), I'm looking for something that can run natively on default images.</li>
  <li>Tags like  can occur elsewhere in the pom, so I can't simply awk for those tags.</li>
  </ol>
  
  <p>I have tried the following:</p>
  
  <ol>
  <li><b><code>xpath</code></b> works on my Mac, but isn't available by default on RHEL machines. Similarly for <code>xmllint --xpath</code>, which I guess is only available on later versions of <code>xmllint</code>, which I don't have and can't enforce.</li>
  <li><b><code>xmllint --pattern</code></b> seemed promising, but I can't seem to get an output out of <code>xmllint --pattern '//project/parent/version' pom.xml</code> (prints entire XML) or <code>xmllint --stream --pattern '//project/parent/version' pom.xml</code> (no output).</li>
  </ol>
  
  <p>I realize this is a common question here on SO, but the points above are why I can't use those answers. TIA for your help.</p>