XML Powered Website

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    XML Powered Website

    Hey Guys!

    Just looking for a point in the right direction to be honest.

    I am looking to run a image site that will grab all the content from a local XML file.

    The site will display a table with 4 thumbnails wide and clicking on the thumbnails will load an external website.

    Does anyone know of any resources that could give me guidance on where to start?

    Thanks,

    Gary

    #2
    php has simpleXML which allows you to treat xml files as arrays, so getting info out of the xml files is relatively straightforward.
    I built a website for a large property rental company that is totaly based on XML ( Leaders) so I know a fair bit about processing xml files. Feel free to ask for more help
    David Allen - www.serina.co.uk

    Comment


      #3
      Thanks for the reply David.

      I have very little knowledge when it comes to XML as I have never used it in web production. I believe this is an example of how my XML file will look like:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <content>
      	<set>
      		<image>http://www.example.com/image1.jpg</image>
      		<link>http://www.example.com/link1.html</link>
      	</set>
      	<set>
      		<image>http://www.example.com/image2.jpg</image>
      		<link>http://www.example.com/link2.html</link>
      	</set>
      	<set>
      		<image>http://www.example.com/image3.jpg</image>
      		<link>http://www.example.com/link3.html</link>
      	</set>
      	<set>
      		<image>http://www.example.com/image4.jpg</image>
      		<link>http://www.example.com/link4.html</link>
      	</set>
      	<set>
      		<image>http://www.example.com/image5.jpg</image>
      		<link>http://www.example.com/link5.html</link>
      	</set>
      	<set>
      		<image>http://www.example.com/image6.jpg</image>
      		<link>http://www.example.com/link6.html</link>
      	</set>
      </content>
      And with this XML code I would like to output itself like this:

      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      </head>
      <body>
      <table width="100%" border="0">
        <tr>
          <td><a href="LINK1"><img src="IMAGE1" /></a></td>
          <td><a href="LINK2"><img src="IMAGE2" /></a></td>
          <td><a href="LINK3"><img src="IMAGE3" /></a></td>
        </tr>
        <tr>
          <td><a href="LINK4"><img src="IMAGE4" /></a></td>
          <td><a href="LINK5"><img src="IMAGE5" /></a></td>
          <td><a href="LINK6"><img src="IMAGE6" /></a></td>
        </tr>
      </table>
      </body>
      </html>
      Any guidance on this would be very much received!!
      Last edited by garygas; 23-04-2011, 18:00.

      Comment


        #4
        Hi

        Code:
        $sxml=simplexml_load_file($your_xml_filename);
        $sets=$sxml->xpath('set');
        foreach ($sets as $s) {
        	echo '<a href="'.$s->link.'"><img src="'.$s->image.'" /></a>';
        }
        Something like that should do it - without the tables (which are considered bad these days)
        David Allen - www.serina.co.uk

        Comment


          #5
          Thanks for the reply, and code - much appreciated.

          However I have one other question - how would I control the number of images posted in a set row?

          For example, the image displayed will be a thumbnail and I would like three thumbnails wide and then start a new line?

          Thanks

          Comment


            #6
            Use a counter, something like:
            Code:
            $i=0;
            $sxml=simplexml_load_file($your_xml_filename);
            $sets=$sxml->xpath('set');
            foreach ($sets as $s) {
            	if ($i++ == 3) {
            		//start a new line and reset $i 
            		echo '<br />';
            		$i=0;
            	}
            	echo '<a href="'.$s->link.'"><img src="'.$s->image.'" /></a>';
            }
            David Allen - www.serina.co.uk

            Comment


              #7
              WOW!!

              I got a test all working and it's perfect!! I think it maybe time to buy a book on XML or something, I think the possibilities with it could be endless, if you know what your doing!

              Thank you very much for your help David.

              Comment


                #8
                You're welcome
                Don't bother with a book - just learn by doing it (and google) - that's what I did
                David Allen - www.serina.co.uk

                Comment


                  #9
                  Hey!

                  Me again....

                  I've run into a bit of an issue. I've used your code and setup a test, however it appears to run the 3 thumbs rule for the first line and then forgets about it for the rest of the page.

                  Here is my test: Untitled Document

                  XML Code:
                  Code:
                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <content>
                  	<set>
                  		<image>1.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>2.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>3.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>4.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>5.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>6.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>7.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>8.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>9.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>1.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>2.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>3.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>4.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>5.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>6.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>7.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>8.png</image>
                  		<link>#</link>
                  	</set>
                  	<set>
                  		<image>9.png</image>
                  		<link>#</link>
                  	</set>
                  </content>
                  PHP Code:
                  Code:
                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns="http://www.w3.org/1999/xhtml">
                  <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                  <title>Untitled Document</title>
                  </head>
                  
                  <body>
                  <?php
                  $i=0;
                  $sxml=simplexml_load_file("test.xml");
                  $sets=$sxml->xpath('set');
                  foreach ($sets as $s) {
                  	if ($i++ == 3) {
                  		//start a new line and reset $i 
                  		echo '<br />';
                  		$i=0;
                  	}
                  	echo '<a href="'.$s->link.'"><img src="'.$s->image.'" /></a>';
                  }
                  ?>
                  </body>
                  </html>

                  Comment


                    #10
                    Try this slight amendment -
                    Code:
                    $i=0;
                    $sxml=simplexml_load_file("test.xml");
                    $sets=$sxml->xpath('set');
                    foreach ($sets as $s) {
                    	echo '<a href="'.$s->link.'"><img src="'.$s->image.'" /></a>';
                    	if ($i++ == 2) {
                    		//start a new line and reset $i 
                    		echo '<br />';
                    		$i=0;
                    	}
                    }
                    works ok for me - see this quick test
                    David Allen - www.serina.co.uk

                    Comment


                      #11
                      Perfect!

                      Please PM me your PayPal, I'd love to give you something for your help!

                      Comment


                        #12
                        XML Powered Websites

                        Use of third-party XML to power web sites is becoming the norm - especially within the retail and service / supply oriented sector today. XML feeds allows the creation of a corporate or e Commerce website to be run (or be powered by XML) solely from a third-party (a supplier) with complete order placement, stock availability querying and dispatch information functionality.

                        Using third-party XML feeds to power web sites allows the user (or website owner) to concentrate on selling and / or promoting the products or services without having to worry about HOW to display the products, checking available stock from the supplier, or having to manually process any orders received via their website (in the case of e Commerce sites or portals).

                        Intellitech I.T. Solutions Ltd. has worked with industry leading suppliers in the travel and the information technology sector to design web sites working primarily using XML feeds which supply the client sites with "raw" data in XML format which the client site processes, stores and can then display to it's web site visitors in a presentable and easy to understand format with pleasing graphical layouts and easy to use search and website navigation interfaces.




                        Comment


                          #13
                          Originally posted by garygas View Post
                          Perfect!

                          Please PM me your PayPal, I'd love to give you something for your help!
                          Gary
                          No need for payment - happy to help. However if you want to give something, my daughter is going off on a charity trip to help in Costa Rica, and any donations to help with the trip would be much appreciated - see My Costa Rica Trip | Serina Allen

                          But really my advice is always free, so don't hesitate to ask again
                          David Allen - www.serina.co.uk

                          Comment

                          Working...
                          X