title: Fetch URL from XML with jQuery and PHP - Jquery Slideshow
body: <p>Im using the jQuery Nivo Slider, its pretty simple to setup:</p>
  
  <pre><code>&lt;link rel="stylesheet" href="nivo-slider.css" type="text/css" media="screen" /&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="jquery.nivo.slider.pack.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;!-- Then somewhere in the &lt;body&gt; section --&gt;
  &lt;div id="slider"&gt;
      &lt;img src="images/slide1.jpg" alt="" /&gt;
      &lt;a href="http://dev7studios.com"&gt;&lt;img src="images/slide2.jpg" alt="" title="#htmlcaption" /&gt;&lt;/a&gt;
      &lt;img src="images/slide3.jpg" alt="" title="This is an example of a caption" /&gt;
      &lt;img src="images/slide4.jpg" alt="" /&gt;
  &lt;/div&gt;
  &lt;div id="htmlcaption" class="nivo-html-caption"&gt;
      &lt;strong&gt;This&lt;/strong&gt; is an example of a &lt;em&gt;HTML&lt;/em&gt; caption with &lt;a href="#"&gt;a link&lt;/a&gt;.
  &lt;/div&gt;
  </code></pre>
  
  <p>However I want to be able to define the Images and captions in a seperate file, perhaps an XML file or text file. I'd like to store the images in a fairly readable fashion so that virtually anyone could update the file if need be.</p>
  
  <p>So question is how can I generate HTML in the same structure as used above by generated automatically via PHP from a file?</p>
  
  <p>I need to generate a list of images with some options:</p>
  
  <p>
  <a href="http://dev7studios.com" rel="nofollow"></a>
  
  </p>
  
  <p>I supposse the options are:</p>
  
  <ol>
  <li>IMG src</li>
  <li>href</li>
  <li>alt</li>
  <li>title (The title relates to the caption)</li>
  <li><p>caption (The actual caption text)</p></li>
  <li><p>Option in the PHP to order the images based on an ID </p></li>
  </ol>
  
  <p>Only the IMG src, alt and title would be compulsary with the remaining fields optional.</p>
  
  <p>I imagine XML is going to be the easiest way to define these options, but I have no idea how to go about creating my own XML. I've already written down the following but I need to know how to correctly define this as XML. E.g. Is there a namespace or something I need to add to the top of the file to create valid XML?</p>
  
  <pre><code>&lt;images&gt;
    &lt;image&gt;
      &lt;id&gt;1&lt;/id&gt;
      &lt;source&gt;images/slide1.jpg&lt;/source&gt;
      &lt;alt&gt;This is an image&lt;/alt&gt;
      &lt;title&gt;caption1&lt;/title&gt;
      &lt;href&gt;http://url.com&lt;/href&gt;
    &lt;image&gt;
    &lt;image&gt;
      &lt;id&gt;3&lt;/id&gt;
      &lt;source&gt;images/slide3.jpg&lt;/source&gt;
      &lt;alt&gt;This is an image&lt;/alt&gt;
      &lt;title&gt;caption3&lt;/title&gt;
      &lt;href&gt;http://url.com&lt;/href&gt;
      &lt;caption&gt;This is an example of a HTML caption.&lt;/caption&gt;
    &lt;image&gt;
    &lt;image&gt;
      &lt;id&gt;2&lt;/id&gt;
      &lt;source&gt;images/slide2.jpg&lt;/source&gt;
      &lt;alt&gt;This is an image&lt;/alt&gt;
      &lt;title&gt;caption2&lt;/title&gt;
      &lt;href&gt;http://url.com&lt;/href&gt;
    &lt;image&gt;
  &lt;/images&gt;
  </code></pre>
  
  <p>So thats potentially the XML defined to store the slider details.</p>
  
  <p>Now I need to read the XML to generate the HTML:</p>
  
  <p>All the images have to be stored between the <code>&lt;div id="slider"&gt; images &lt;/div&gt;</code> and the captions have to be defined outside of this .</p>
  
  <p>So I need to fetch the images first in the corret order based on the ID <code>&lt;id&gt;</code>. Something like (Not real code).</p>
  
  <pre><code>foreach image as images {
    $id = &lt;id&gt;;
    $src = &lt;src&gt;;
    $title = &lt;title&gt;; 
    $alt = &lt;alt&gt;;
    $href = &lt;href&gt;;
    orderby $id;
  
    &lt;!--HERE I NEED TO DO SOME KIND OF if HERE SO THAT ONLY THOSE ELEMENTS
        THAT ARE POPULATED IN THE XML ARE USED
     --&gt;
  
    echo "&lt;a href='$href'&gt;&lt;img src='$src' alt='$alt' title='$title' /&gt;&lt;/a&gt;";
  
  }
  </code></pre>
  
  <p>The above would loop 3 times based on the above XML, and output the full HTML ready for a caption.</p>
  
  <p>So to generate the captions I need to create this:</p>
  
  <pre><code>foreach images as image {
    if $title = * {
      echo "&lt;div id='$title' class='nivo-html-caption'&gt;
              This is an example of a HTML caption.
            &lt;/div&gt;"
    }
  }
  </code></pre>
  
  <p>I beleive the <code>Title</code> give to the <code>&lt;img&gt;</code> is the relative to the <code>ID</code> given to the <code>nivo-html-caption</code> <code>ID</code>. </p>
  
  <p>I realise I've written a lot here but just done have the understanding of XML to put the file together in a valid way.</p>
  
  <p>How can I fetch the file using PHP?</p>
  
  <p>How can I loop through the XML to generate the Images in HTML and put them in the correct order?</p>
  
  <p>How can I generate the HTML captions seperatly?</p>
  
  <p>Any help greatly appreciated!</p>