Advanced Search

Results 1 to 3 of 3

Thread: Loading Image from XML file

  1. #1
    Join Date
    Jun 2008
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Loading Image from XML file

    I have been using a flash file to read an xml file that reads the location of an image and displays it.

    Here is an example of the XML file:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <icons>
    
    <icon image="images/thmbs/set29.jpg" titre="Set 28" desc="POSTED 5-27-08"/>
    <icon image="images/thmbs/set27.jpg" titre="Set 27" desc="POSTED 5-23-08"/>
    <icon image="images/thmbs/set30.jpg" titre="Set 26" desc="POSTED 5-20-08"/>
    
    </icons>
    I am trying to move away from flash, and find a Jscript or Ajax solution to display the images from that same xml file.

    Been playing with:
    http://www.dynamicdrive.com/dynamicindex11/ajax.htm

    But cannot get it to display anything, dunno what I am doing wrong.

    Any help would be great.

    To be clear, the goal is not to display the url of the image as text but to pull the url and put it into a div or img tag, but display the title/desc as text. Also want to be able to limit the number of nodes it loads, like do the first 4 or the first 8, that way I could have more then 8 nodes but it will only load the first 8 and stop.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,704
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    If you are to use the:

    http://www.dynamicdrive.com/dynamicindex11/ajax.htm

    script as written, you need to change the icon tags to img tags:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <icons>
    
    <img src="images/thmbs/set29.jpg" alt="Set 28" title="POSTED 5-27-08"/>
    <img src="images/thmbs/set27.jpg" alt="Set 27" title="POSTED 5-23-08"/>
    <img src="images/thmbs/set30.jpg" alt="Set 26" title="POSTED 5-20-08"/>
    
    </icons>
    Let's call that img.xml. And, to work locally, you need a slight modification to the script:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    
    /******************************************
    * Ajax load XML file script -- By Eddie Traversa (http://dhtmlnirvana.com/)
    * Script featured on Dynamic Drive (http://www.dynamicdrive.com/)
    * Keep this notice intact for use
    ******************************************/
       
       function ajaxLoader(url,id)
    	{
    		if (document.getElementById) {
    			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    			}
    			if (x)
    				{
    			x.onreadystatechange = function()
    					{
    				if (x.readyState == 4 && (x.status == 200 || !/^http/.test(location.href)))
    						{
    						el = document.getElementById(id);
    						el.innerHTML = x.responseText;
    					}
    					}
    				x.open("GET", url, true);
    				x.send(null);
    				}
    	    }
    
    </script>
    </head>
    <body onload="ajaxLoader('img.xml','contentLYR')">
    <div id="contentLYR">
    </div>
    </body>
    </html>
    Here's a demo:

    http://home.comcast.net/~jscheuer1/side/xml_img/

    However, since you didn't give us the paths to the images, all you will see are the alt values.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    In addition to this code, i want to populate each image into a HTML table into diffrent rows or may be diff <td> elements.
    Right now, all image files are improting together.
    I want to access them saparatly in HTML table.

    How can i do that ?
    Thanks in advance.

    -MV

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •