title: Filter xml file using Javascript
body: <p>I am trying to rebuild an old application without the loss of data. The current data has all been stored in xml files that i am trying to read using Javascript.</p>
  
  <p>This is the Javascript (i'm new to this, feedback is appreciated):</p>
  
  <pre><code>// Create a connection to the file.
              var Connect = new XMLHttpRequest();
  
              // Define which file to open and
              // send the request.
              Connect.open("GET", "writers.xml", false);
              Connect.setRequestHeader("Content-Type", "text/xml");
              Connect.send(null);
  
              // Place the response in an XML document.
              var TheDocument = Connect.responseXML;
  
              // Place the root node in an element.
              var Customers = TheDocument.childNodes[0];
  
              // Retrieve each customer in turn.
              for (var i = 0; i &lt; Customers.children.length; i++){
                  var Customer = Customers.children[i];
                  //Create div's for data
                  document.getElementById("body").innerHTML += "&lt;div id='who" + i + "'&gt;&lt;/div&gt;"
                  document.getElementById("body").innerHTML += "&lt;div id='age" + i + "'&gt;&lt;/div&gt;"
                  document.getElementById("body").innerHTML += "&lt;div id='hobby" + i + "'&gt;&lt;/div&gt;"
                  document.getElementById("body").innerHTML += "&lt;div id='image" + i + "'&gt;&lt;/div&gt;"
                  document.getElementById("body").innerHTML += "&lt;div id='something" + i + "'&gt;&lt;/div&gt;"
                  //Assign data to correct divs
                  var who = Customer.getElementsByTagName("name");
                  var who2 = who[0].textContent.toString();
                  document.getElementById("who"+i).innerHTML += who2;
  
                  var age = Customer.getElementsByTagName("age");
                  var age2 = age[0].textContent.toString();
                  document.getElementById("age"+i).innerHTML += age2;
  
                  var hobby = Customer.getElementsByTagName("hobby");
                  var hobby2 = hobby[0].textContent.toString();
                  document.getElementById("hobby"+i).innerHTML += hobby2;
  
                  var image = Customer.getElementsByTagName("image");
                  var image2 = image[0].textContent.toString();
                  document.getElementById("image"+i).innerHTML += image2;
  
                  var something = Customer.getElementsByTagName("something");
                  var something2 = something[0].textContent.toString();
                  document.getElementById("something"+i).innerHTML += something2;
              }
  </code></pre>
  
  <p>This is an example of my xml file:</p>
  
  <pre><code>&lt;doc&gt;
  &lt;person&gt;
      &lt;name&gt;Paul&lt;/name&gt;
      &lt;age&gt;21&lt;/age&gt;
      &lt;hobby&gt;blabla&lt;/hobby&gt;
      &lt;image&gt;thisisanimage.jpg&lt;/image&gt;
      &lt;something&gt;Random string&lt;/something&gt;
  &lt;/person&gt;
  &lt;person&gt;
      &lt;name&gt;Peter&lt;/name&gt;
      &lt;age&gt;&lt;/age&gt;
      &lt;hobby&gt;blabla&lt;/hobby&gt;
      &lt;image&gt;thisisanimage.jpg&lt;/image&gt;
      &lt;something&gt;Random string&lt;/something&gt;
  &lt;/person&gt;
  &lt;/doc&gt;
  </code></pre>
  
  <p>Now i am trying to filter Peter out, because the age field is empty. Anyone got an idea?</p>