title: Replace an XML element's value? Sed regular expression?
body: <p>I want to take an XML file and replace an element's value.  For example if my XML file looks like this:</p>
  
  <pre><code>&lt;abc&gt;
      &lt;xyz&gt;original&lt;/xyz&gt;
  &lt;/abc&gt;
  </code></pre>
  
  <p>I want to replace the xyz element's original value, whatever it may be, with another string so that the resulting file looks like this:</p>
  
  <pre><code>&lt;abc&gt;
      &lt;xyz&gt;replacement&lt;/xyz&gt;
  &lt;/abc&gt;
  </code></pre>
  
  <p>How would you do this?  I know I could write a Java program to do this but I assume that that's overkill for replacing a single element's value and that this could be easily done using sed to do a substitution using a regular expression.  However I'm less than novice with that command and I'm hoping some kind soul reading this will be able to spoon feed me the correct regular expression for the job.</p>
  
  <p>One idea is to do something like this:</p>
  
  <pre><code>sed s/\&lt;xyz\&gt;.*\&lt;\\xyz\&gt;/\&lt;xyz\&gt;replacement\&lt;\\xyz\&gt;/ &lt;original.xml &gt;new.xml
  </code></pre>
  
  <p>Maybe it's better for me to just replace the entire line of the file with what I want it to be, since I will know the element name and the new value I want to use?  But this assumes that the element in question is on a single line and that no other XML data is on the same line.  I'd rather have a command which will basically replace element xyz's value with a new string that I specify and not have to worry if the element is all on one line or not, etc.</p>
  
  <p>If sed is not the best tool for this job then please dial me in to a better approach.</p>
  
  <p>If anyone can steer me in the right direction I'll really appreciate it, you'll probably save me hours of trial and error.  Thanks in advance!</p>
  
  <p>--James</p>