title: modify xml using javascript
body: <p>I am starting to learn xml and I am facing a problem. I need to add elements to the xml file so I use this method:</p>
  
  <pre><code>function newNode() 
  {
      var xmlDoc = loadXMLDoc("Nodes.xml");
  
      var nodes = xmlDoc.documentElement;
      var newNode = xmlDoc.createElement('node');
      var newName = xmlDoc.createElement('name');
      var newText = xmlDoc.createTextNode('Start Node');
  
      newName.appendChild(newText);
      newNode.appendChild(newName);
      xmlDoc.documentElement.appendChild(newNode);
  
      alert(xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue);
  
      return xmlDoc;
  }
  </code></pre>
  
  <p>it works fine and the alert shows "Start Node", but when I use the same alert command as in:</p>
  
  <pre><code>function z() 
  {
      var xmlDoc = loadXMLDoc("Nodes.xml");
      alert(xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue);
  }
  </code></pre>
  
  <p>I get this error:  <em>Unable to get value of the property 'childNodes': object is null or undefined.</em></p>