title: Using C# Regular expression to replace XML element content
body: <p>I'm writing some code that handles logging xml data and I would like to be able to replace the content of certain elements (eg passwords) in the document.  I'd rather not serialize and parse the document as my code will be handling a variety of schemas.</p>
  
  <p>Sample input documents:</p>
  
  <p>doc #1:</p>
  
  <pre><code>   &lt;user&gt;
         &lt;userid&gt;jsmith&lt;/userid&gt;
         &lt;password&gt;myPword&lt;/password&gt;
      &lt;/user&gt;
  </code></pre>
  
  <p>doc #2:</p>
  
  <pre><code>&lt;secinfo&gt;
         &lt;ns:username&gt;jsmith&lt;/ns:username&gt;
         &lt;ns:password&gt;myPword&lt;/ns:password&gt;
   &lt;/secinfo&gt;
  </code></pre>
  
  <p>What I'd like my output to be:</p>
  
  <p>output doc #1:</p>
  
  <pre><code>&lt;user&gt;
         &lt;userid&gt;jsmith&lt;/userid&gt;
         &lt;password&gt;XXXXX&lt;/password&gt;
   &lt;/user&gt;
  </code></pre>
  
  <p>output doc #2: </p>
  
  <pre><code>&lt;secinfo&gt;
         &lt;ns:username&gt;jsmith&lt;/ns:username&gt;
         &lt;ns:password&gt;XXXXX&lt;/ns:password&gt;
   &lt;/secinfo&gt;
  </code></pre>
  
  <p>Since the documents I'll be processing could have a variety of schemas, I was hoping to come up with a nice generic regular expression solution that could find elements with password in them and mask the content accordingly.</p>
  
  <p>Can I solve this using regular expressions and C# or is there a more efficient way?</p>