By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

Creating simple unordered list menu from XML?

P: n/a
Does anyone have any examples or links to examples of generating a
simple unordered list menu with multiple levels from an XML file? We
are redesigning the navigation on our website and I was hoping to make
this as flexible as possible.

Thanks,
Mike
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Michael Champagne scribbled something along the lines of:
Does anyone have any examples or links to examples of generating a
simple unordered list menu with multiple levels from an XML file? We
are redesigning the navigation on our website and I was hoping to make
this as flexible as possible.

Thanks,
Mike


http://www.php.net/xml

You could have a simple structure like

<?xml version="1.0"?>
<menu xmlns="http://www.example.com/menu" label="Navigation">
<category label="My stuff">
<entry label="Chimpanzee" href="/index/chimp"/>
<entry label="Red car" href="/index/car"/>
<category label="My weapons">
<entry label="One-handed sword" href="/index/weaps/sword"/>
<entry label="Battle Axe" href="/index/weaps/axe"/>
</category>
</category>
<category label="Random words">
<entry label="Zilch" href="/index/zilch"/>
<entry label="Squee" href="/index/squee"/>
<entry label="Splurt" href="/index/splurt/">
</category>
</menu>

And all you'd need would be a start-tag and end-tag element handler to
create the following partial HTML:

<h2>Navigation</h2>
<ul>
<li class="category">My stuff<ul>
<li><a href="/index/chimp/">Chimpanzee</a></li>
<li><a href="/index/car/">Red car</a></li>
<li class="category">My weapons<ul>
<li><a href="/index/weaps/sword/">One-handed sword</a></li>
<li><a href="/index/weaps/axe/">Battle Axe</a></li>
</ul></li>
</ul></li>
<li class="category">Random words<ul>
<li><a href="/index/zilch/">Zilch</a></li>
<li><a href="/index/squee/">Squee</a></li>
<li><a href="/index/splurt/">Splurt</a></li>
</ul></li>
</ul>

which could for example render like this:

*Navigation*

# /My stuff/
o _Chimpanzee_
o _Red_car_
o /My weapons/
+ _One-handed_sword_
+ _Battle_Axe_
# /Random words/
o _Zilch_
o _Squee_
o _Splurt_
You could also just use XSLT, but that's a little more complicated (IMHO).
The manual should tell you enough that you can do this on your own. If
you want me to write a script for you though, feel free to transfer 75
to my PayPal account and I'll write you a simple function that does
what I just described.
--
Alan Plum, WAD/WD, Mushroom Cloud Productions
http://www.mushroom-cloud.com/
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.