title: Implementing Images in HTML using XML
body: <p>Okay, so I'm designing a website with the use of HTML, CSS, and (hopefully) XML. There's a specific section of the website I'm trying to use XML for, and I'm having some difficulties incorporating XML the way I want to.</p>
  
  <p>My problem is I'm trying to find a way to read an image (or an image directory) with XML and print it out onto my HTML website using call commands through a for loop, so I can simply input the data into the XML file with attributes and easily call them for any page on the site. I was also looking to eventually add on a search bar, and I've been told that XML would be a great add-on because of the attributes and elements you can add.
  <em>Edit</em>: I believe I'm using the wrong command pulling the images into XML. Any info on that would be helpful.</p>
  
  <p><em>Note: For simplicity reasons, I've stripped down the coding on HTML and XML to what I'm having problems with.</em></p>
  
  <p><em>Here's my XML file</em></p>
  
  <pre><code>&lt;inventory&gt;
  &lt;shirt&gt;
      &lt;picture&gt;&lt;image href="tank_top.jpg"/&gt;&lt;/picture&gt;
      &lt;name&gt;Tank Top&lt;/name&gt;
      &lt;description&gt;This is a tank top. &lt;/description&gt;
      &lt;price&gt;$12.00&lt;/price&gt;
  &lt;/shirt&gt;
  &lt;shirt&gt;
      &lt;picture&gt;&lt;image href="sweater.jpg"/&gt;&lt;/picture&gt;
      &lt;name&gt;Sweater&lt;/name&gt;
      &lt;description&gt;This is a sweater. &lt;/description&gt;
      &lt;price&gt;$15.00 &lt;/price&gt;
  &lt;/shirt&gt;
  &lt;shirt&gt;
      &lt;picture&gt;&lt;image href="hoodie.jpg"/&gt;&lt;/picture&gt;
      &lt;name&gt;Hoodie&lt;/name&gt;
      &lt;description&gt;This is a hoodie. &lt;/description&gt;
      &lt;price&gt;$17.00 &lt;/price&gt;
  &lt;/shirt&gt;
  &lt;shirt&gt;
      &lt;picture&gt;&lt;image href="long_sleeve_shirt.jpg"/&gt;&lt;/picture&gt;
      &lt;name&gt;Long-Sleeve&lt;/name&gt;
      &lt;description&gt;This is a long-sleeve. &lt;/description&gt;
      &lt;price&gt;$20.00 &lt;/price&gt;
  &lt;/shirt&gt;
  &lt;shirt&gt;
      &lt;picture&gt;&lt;image href="t-shirt.jpg"/&gt;&lt;/picture&gt;
      &lt;name&gt;T-Shirt&lt;/name&gt;
      &lt;description&gt;This is a t-shirt. &lt;/description&gt;
      &lt;price&gt;$50.00 &lt;/price&gt;
  &lt;/shirt&gt;
  &lt;/inventory&gt;
  </code></pre>
  
  <p><em>Here's my Javascript</em></p>
  
  <pre><code>if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.open("GET","Example.xml",false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML; 
  
  var x=xmlDoc.getElementsByTagName("shirt");
   for (i=1;i&amp;lt;x.length+1;i++)
    {
     document.write(x[i].getElementsByTagName("picture")[0].childNodes[0].nodeValue);
     document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
     document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
     document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
    }
  </code></pre>
  
  <p>I even tried using the below code in place of the first "document.write" command for the picture,</p>
  
  <blockquote>
    <p>var img=new Image();
          img.src='insert_image_title_here';
          document.body.appendChild( img );</p>
  </blockquote>
  
  <p>but this only sent my image to the bottom of the page after everything else loaded. And I need to load different titled images every time the rest of the information is printed out (i.e. I need the picture printed, then the name, then description, and then price. Then a different pictured along with its own information that is stored in the XML file).</p>
  
  <p>TL;DR:
  I need to output an image in HTML, going through JS, that reads an XML file. And I need the XML file to pull the image because of a for loop I have the print commands nested in. Simplified XML and HTML codes are above.
  Looked for hours for a solution. Found nothing helpful.</p>
  
  <p><em>Note: I'm only in high school, and although I've been coding for a couple years (mainly with Java and dabbled in HTML) I'm very new to the rest of the coding world... I've actually just started learning to use XML today. Any and all descriptions would be amazingly helpful. And please include any web sources or even books you think may be of help. Thanks so much!</em></p>