Location: PHPKode > scripts > Menu Handling Class with SimpleXML and PHP > menu-handling-class-with-simplexml-and-php/class/xml.menu.class.php
<?php
class XMLNavigation
{
	function PrepareMenu($url, $txt, $navid, $path, $matching1, $matching2, $psub1, $psub2, $pmain)
	{

	$xml = simplexml_load_file($path);	
	$xmlsub = simplexml_load_file($path);
	$id = $_GET[$navid];	
	$pathsub = "$psub1"."["."@".$psub2."=".$id."]";
	$pathmain = $pmain;
	
	echo "<a href=$url>$txt <<</a><br/>";

	if(!isset($_GET[$navid]))
		{
			$res = $xmlsub->xpath($pathmain);		
			for ($x=0; $x < sizeof($res); $x++)
			{
					$uri	= $res[$x]->uritext;
					$url	= $res[$x]->urltext;
					$a	= $res[$x]->attributes();
					echo "&nbsp;->&nbsp;<a href=$url?pageid=$a>$uri</a><br/>";
			}		
		}
		
	if(isset($_GET[$navid]))
	{		
		if ($res = $xmlsub->xpath($pathmain))
		{
			for ($x=0; $x < $id; $x++)
			{
				foreach($xml->link[$x]->attributes() as $a => $b)
				{
					$uri = $res[$x]->uritext;
					$url = $res[$x]->urltext;
					echo "&nbsp;->&nbsp;<a href=$url?pageid=$b>$uri</a><br/>";
				}
			}
		}	
			
		if ($res = $xmlsub->xpath($pathsub))
		{
			for ($x=0; $x < sizeof($res); $x++)
			{
				$uri = $res[$x]->urisubtext;
				$url = $res[$x]->urlsubtext;
				echo "&nbsp;&nbsp;&nbsp;->&nbsp;<a href=$url>$uri</a><br/>";
			}
		}			
			
		if ($result = $xmlsub->xpath($pathmain))
		{
			for ($y=$id; $y < sizeof($result); $y++)
			{
					$uri	= $result[$y]->uritext;
					$url	= $result[$y]->urltext;
					$d	= $result[$y]->attributes();
					echo "&nbsp;->&nbsp;<a href=$url?pageid=$d>$uri</a><br/>";
			}
		}	
	}
   }
}
?>		
Return current item: Menu Handling Class with SimpleXML and PHP