title: javascript table format output
body: <p>I have this JavaScript html code for getting the tabular format output. I am giving XML data as input to the script.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction() {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(
    "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"
    +"&lt;book&gt;"+
    "&lt;title&gt;The Time Machine and Other Stories&lt;/title&gt;"+
    "&lt;author_name&gt;H. G. Wells&lt;/author_name&gt;"+
    "&lt;publish_date&gt;2016&lt;/publish_date&gt;"+
    "&lt;cost currency=\"USD\"&gt;10&lt;/cost&gt;"+
    "&lt;publisher_info&gt;"+ 
    "&lt;publisher_name&gt;Read Books Ltd&lt;/publisher_name&gt;"+
    "&lt;publisher_address&gt;"+
    "&lt;street_name&gt;Evesham street&lt;/street_name&gt;"+
    "&lt;city&gt;Worcestershire&lt;/city&gt;"+
    "&lt;zip_code&gt;11WR&lt;/zip_code&gt;"+
    "&lt;country&gt;United Kingdom&lt;/country&gt;"+
    "&lt;/publisher_address&gt;"+
    "&lt;/publisher_info&gt;"+
    "&lt;/book&gt;","text/xml");
  
    var x=xmlDoc.getElementsByTagName("publisher_address");
    
    for (i=0;i&lt;x.length;i++) { 
      document.write("&lt;tr&gt;");
      var y=x[i].childNodes;
      for (j=0;j&lt;y.length;j++) {
        document.write("&lt;td&gt;"+ y[j].childNodes[0].nodeValue+ "&lt;/td&gt;");
      }
      document.write("&lt;/tr&gt;");
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>table, th, td {
    border: 1px solid black;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;h1&gt;My First XML Parsing JavaScript&lt;/h1&gt;
  &lt;p&gt;Click the button to display book info.&lt;/p&gt;
  &lt;p id="demo"&gt;&lt;/p&gt;
  &lt;button type="button" onclick="myFunction()"&gt;Try it&lt;/button&gt;
  &lt;table border="0"&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The output I am getting is:</p>
  
  <blockquote>
    <p>Evesham streetWorcestershire11WRUnited Kingdom</p>
  </blockquote>
  
  <p>Can anyone help me why I am not able to get output in tabular format?</p>