I'm starting from the bottom of XML and all I want to do is display the elements of one tag. You'll understand what I mean if you look at the code.

    <script type="text/javascript">
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     <![CDATA[ document.write("<tr><img src='http://imgur.com/' + 'hash'></img></tr>")]]>

Thanks for the help

Recommended Answers

All 3 Replies

I think you have to call getElementsByTagName from the xmlDoc object


Are you thinking of using the hash value in the <img> src? Because you haven't assigned the node value to any variable.

var hashNodeValue = xmlDoc.getElementsByTagName("hash")[0].childNodes[0].nodeValue;
// Are you thinking about using this hashNodeValue in
// document.write("<tr><img src='http://imgur.com/' + 'hash'></img></tr>") ?

The other thing is, Is it possible to access a file in an other domain using xmlhttp.open?

I hope I understood your question correctly.

I'm not sure I'm even going about this the right way. I wanted to use an array of the length of results the xml document had. (number of hash tags) Then all I wanted to do is reproduce the image (using the hash tag and adding it to the url). Using a for loop, I'd be able to write each image to the document. And yes, I'm pretty sure you can access the xml document even though its on another domain. Its just a feed.

If you are sure that you can access http://imgur.com/r/funny.xml through xmlhttp.open following should work. Actually http://imgur.com/r/funny.xml did not worked for me. So I downloaded the XML and tested it.

	if (xmlhttp.readyState==4 && xmlhttp.status==200)
		var xmlText = xmlhttp.responseXML;
		var hashTags = xmlText.getElementsByTagName("hash");
		var ext = xmlText.getElementsByTagName("ext");
		var imageHash = new Array();
		for(var i = 0; i < hashTags.length; i++)
			// If you want to store in an array
			imageHash[i] = hashTags[i].childNodes[0].nodeValue + ext[i].childNodes[0].nodeValue;
			// If you want to reproduce images
			document.write("<img src='http://i.imgur.com/"+(hashTags[i].childNodes[0].nodeValue + ext[i].childNodes[0].nodeValue)+"'><br/>");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.