title: Update or inserting a node in an XML doc
body: <p>I am a beginner to XML and XPath in C#. Here is an example of my XML doc:</p>
  
  <pre><code> &lt;root&gt;
     &lt;folder1&gt;
     ...
     &lt;folderN&gt;
        ...
        &lt;nodeMustExist&gt;...
        &lt;nodeToBeUpdated&gt;some value&lt;/nodeToBeUpdated&gt;
    ....
   &lt;/root&gt;
  </code></pre>
  
  <p>What I need is to update the value of nodeToBeUdpated if the node exists or add this node after the nodeMustExist if nodeToBeUpdated is not there. The prototype of the function is something like this:</p>
  
  <pre><code>void UpdateNode(
                    xmlDocument xml, 
                    string nodeMustExist, 
                    string nodeToBeUpdte, 
                    string newVal
                 )
  {
     /*
  
     search for XMLNode with name = nodeToBeUpdate in xml 
     to XmlNodeToBeUpdated (XmlNode type?)
     if (xmlNodeToBeUpdated != null)
     {
        xmlNodeToBeUpdated.value(?) = newVal;
     }
     else
     {
        search for nodeMustExist in xml to xmlNodeMustExist obj
        if ( xmlNodeMustExist != null )
        {
            add xmlNodeToBeUpdated as next node
            xmlNodeToBeUpdte.value = newVal;
         }
      }
  
     */
  }
  </code></pre>
  
  <p>Maybe there are other better and simplified way to do this. Any advice?</p>
  
  <p>By the way, if nodeToBeUpdated appears more than once in other places, I just want to update the first one.</p>