• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

XML Menu to HTML!

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
53
Location
Włocławek
Hello guys! I made easy parser XML to HTML menu : ))
You can add style for generated links easy, and display method (ex. Im using <ul> <li> <a[...]>hyperlink</a></li><ul>) : )
Can be multi list (ex. <ul><li>link</li><ul><li>sidelink</li></ul></ul>) - im using it for JQuery wrap menu. : ))
I made it, because need for my site and i post here it for all : )


file: class.XMLMenu.php
PHP:
<?PHP
	class parseMenu {
		
		private $linkPattern;
		private $listingStyle;
		private $XML;
		private $menuContents = "";
		private $patternReplaces = array("+LINK_HREF+", "+LINK_NAME+"); 
	
		public function __construct($menuFile, $linkPattern, $listingStyle=array("<UL>", "</UL>", "<LI>", "</LI>")){
			$this->menuFile = $menuFile;
			$this->linkPattern = $linkPattern;
			$this->listingStyle = $listingStyle;
			$this->loadMenu($menuFile);
		}
		
		private function loadMenu($menuFile){
			@$f_load = simplexml_load_file($menuFile);
			if(!$f_load) die("Cannot load or parse menu file.");
			return $this->XML = $f_load;
		}
		
		public function getMenu($link=false){
			if(!$link) $link = @$this->XML->link;
			if(count($link) > 0){
				$this->menuContents.=$this->listingStyle[0];
				foreach($link as $_link){
					$this->menuContents.=$this->listingStyle[2].$this->stylizeLink($_link).$this->listingStyle[3];
					if(count($_link->link) > 0){
						$this->getMenu($_link->link);
					}
				}
				$this->menuContents.=$this->listingStyle[1];
				return $this->menuContents;
			}
		}
		
		private function stylizeLink($link){
			return str_replace($this->patternReplaces, array($link["href"], $link["name"]), $this->linkPattern);
		}
		
	
	}
?>

now, example for using... : )
PHP:
<?PHP
	include("class.XMLMenu.php");
	echo "<h2>MENU</h2>";
	$menu = new parseMenu("menu.xml", "<a style=\"color:red;\" href=\"+LINK_HREF+\">+LINK_NAME+</a>", array("<UL>", "</UL>", "<LI>", "</LI>"));
	echo $menu->getMenu();
?>

example menu XML file:
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
	<link href="index.html" name="Home" />
	<link href="about_me.html" name="About Me" >
		<link href="about_me,profile.html" name="My Profile" />
		<link href="about_me,portfolio.html" name="Portfolio" />
	</link>
	<link href="/forum/index.html" name="Forums" />
	<link href="download.html" name="Download">
		<link href="download,music.html" name="Music">
			<link href="download,music_rap.html" name="Rap">
				<link href="download,2pac.html" name="2Pac">
					<link href="download,2pac_album1.html" name="First Album"/>
					<link href="download,2pac_album2.html" name="Second Album"/>
					<link href="download,2pac_album3.html" name="Third Album"/>
					<link href="download,2pac_album4.html" name="Fourth Album"/>
					<link href="download,2pac_album5.html" name="Fifth Album"/>
					
				</link>
				<link href="download,50cent.html" name="50Cent">
					<link href="download,50cent_album1.html" name="First Album"/>
					<link href="download,50cent_album2.html" name="Second Album"/>
					<link href="download,50cent_album3.html" name="Third Album"/>
				</link>
			</link>
			<link href="download,music_rap.html" name="Other">
				<link href="download,to_the_left_mp3.html" name="To the left.mp3"/>
				<link href="download,hang_up_mp3.html" name="Hang up.mp3"/>
			</link>
		</link>
		<link href="games.html" name="Games">
			<link href="download,icy_tower_exe.html" name="Icy Tower"/>
			<link href="download,tibia_exe.html" name="Tibia"/>
		</link>
	</link>
	<link href="contact.html" name="Contact" >
		<link href="contact,via_www.html" name="Via WWW">
			<link href="contact,info.html" name="Contact Info" />
			<link href="contact,post.html" name="Post Message" />
		</link>
		<link href="contact,via_msn.html" name="Via MSN" />
	</link>
	<link href="contact,banners.html" name="Banners" />

	
</menu>

In example im using multi-listing!

USING:
parseMenu(MENU XML FILE, HYPERLINK DISPLAY PATTERN"[, LIST STYLING'S])

DISPLAY PATTERN KEYS
- "+LINK_HREF+" - returns hyperlink url here
- "+LINK_NAME+" - returns hyperlink mask name here

getMenu() <- for display menu : )

Screen of example:
examplem.jpg


Thanks, Your Azi!
 
Back
Top