title: DOM XML: getElementsByTagName(...)[0] is undefined
body: <p>I am generating an XML file with JavaScript, when I iterate over an array of objects to enter the data in the XML it gives me the error that you see in the title. I am generating ROW nodes in which I want to put certain elements. My problem starts when I try to access X position of an element or when I try to add it to the node.</p>
  <pre><code>this.array.forEach((element) =&gt; {
      var node = xmlDoc.createElement(&quot;ROW&quot;);
      var row = xmlDoc.getElementsByTagName(&quot;ROW&quot;);
  
      var fecha = xmlDoc.createElement(&quot;DATE&quot;);
      xmlDoc.getElementsByTagName(&quot;DATE&quot;)[0].textContent = element.fecha;
      row[0].appendChild(fecha);
  
      var descripcion1 = xmlDoc.createElement(&quot;DESCRIPTION&quot;);
      xmlDoc.getElementsByTagName(&quot;DESCRIPTION&quot;)[0].textContent =
        element.descripcion1;
      row[0].appendChild(descripcion1);
  
      var descripcion2 = xmlDoc.createElement(&quot;DESCRIPTION2&quot;);
      xmlDoc.getElementsByTagName(&quot;DESCRIPTION2&quot;)[0].textContent =
        element.descripcion2;
      row[0].appendChild(descripcion2);
  
      var nombre = xmlDoc.createElement(&quot;NAME&quot;);
      xmlDoc.getElementsByTagName(&quot;NAME&quot;)[0].textContent = element.nombre;
      row[0].appendChild(nombre);
  
      rowset[0].appendChild(node);
    });
  </code></pre>
  <p>Here I leave you how I have generated the XML.</p>
  <pre><code>var xmlDoc = document.implementation.createDocument(null, &quot;filename&quot;);
  
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
      if (xhttp.readyState == 4 &amp;&amp; xhttp.status == 200) {
        var xmlDoc = xhttp.responseXML;
      }
      xhttp.open(&quot;GET&quot;, &quot;filename.xml&quot;, true);
      xhttp.send();
    };
  
    var xmlString = &quot;&lt;ROWSET&gt;&lt;/ROWSET&gt;&quot;;
    var parser = new DOMParser();
    var xmlDoc = parser.parseFromString(xmlString, &quot;text/xml&quot;);
  
    var rowset = xmlDoc.getElementsByTagName(&quot;ROWSET&quot;);
  </code></pre>