I have an XML file that lists all the services I provide to my customers.

I can populate a list from this file easily.
What I'd like to do is when someone clicks on a particular service, then I display the description of that particular service.
I think I need to use xpath, but not sure how....

My xml file look like this:

<services>

<service >
<id>1</id>
<title>Website Design and Programming </title>
<desc>blah blah </desc>
</service>

<service >
<id>2</id>
<title>Database Programming </title>
<desc>wrfwrfwrf </desc>
</service>

<service >
<id>3</id>
<title>Web Development (PHP, XHTML, JavaScript, CSS, AJAX)</title>
<desc>some text </desc>
</service>
</services>

PHP code to display a list of all services:

<ul>
<? 
	$Data=simplexml_load_file('services.xml');
	foreach ($Data->service as $service)
	{

foreach ($service->id as $id)
	{
	foreach ($service->title as $title)
	{
	?>
  <li><a href="display.php?Service=<? echo $id;?>" title="<? echo $title;?>"><? echo $title;?></a></li>
   <? }	} }?>
</ul>

On the display page I only want to show the description of the service that's been clicked.

Eventually I'd like to use jquery ajax call to load the description on the same page , but that's another story 🙂

Help is greatly appreciated, tx, kamy

    you can do it easily with xpath... I don't have my "toolbox" in front of me at the moment but I can find some examples later if you cant figure it out

      $container = $Data->query("parent:://id[contains(.,'"$_GET['id']"')]");
      echo $container->description->nodeValue;
      

      something roughly along those lines

        Thanks, that certainly helped greatly!

        I achieved it with a foreach loop.

        $Data=simplexml_load_file('services.xml');
        
        $result = $Data->xpath('/services/service[id='.$_GET["Service"].']');
        
        foreach ($result as $desc)
        {
        echo "<div id=ServiceTitle>".$desc->title."</div>"; 
        echo "<div id=ServiceDesc>".$desc->desc."</div>";
          }	

        What you think?

          Write a Reply...