URGENT - XML with n numbers of nested categories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
seopower
Forum Newbie
Posts: 2
Joined: Mon Jul 09, 2007 2:58 am

URGENT - XML with n numbers of nested categories

Post by seopower »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a XML which can have n number of nested categories and subcategories. The problem is node names are all same for each level. Now can any please tell how can I display names with relation between each?

Or how will loop work or any other method of getting values?

I mean display should be:

Category 1
  - Subcategory
        - More Subcategory
Category 2
  - Subcategory
        - More Subcategory

and so on....

The XML I am having is something like this:

[syntax="xml"]
<taxonomy>
 <form id="96451" name="Cars">
  <taxonomy>
    <form id="96477" name="Auto Parts and Accessories"></form>
    <form id="96621" name="Automotive Security Systems"></form>
    <form id="96478" name="Motorcycle Parts and Accessories"></form>
    <form id="96456" name="New Cars">
    <form id="96457" name="Used Cars"></form>
  </taxonomy>
 </form>
 <form id="2010" name="Clothing and Accessories">
  <taxonomy>
    <form id="31515" name="Clothing"></form>
    <form id="68185" name="Luggage"></form>
    <form id="96602" name="Shoes"></form>
  </taxonomy>
 </form>
</taxonomy>


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and/or xsl(t)

e.g.

Code: Select all

<?php
$xsl_s = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="iso-8859-1" indent="no"/>
  <xsl:template match="node">
    <fieldset><legend><xsl:value-of select="@id" /></legend>
      <xsl:apply-templates/>
    </fieldset>
   </xsl:template>
  <xsl:template match="value">
  <xsl:apply-templates/>
    </xsl:template>
  </xsl:stylesheet>
';

$xml_s = '<node id="1">
  <value>a</value>
  <value>b</value>
  <value>c</value>
  <node id="2">
    <value>d</value>
    <node id="3">
      <value>e</value>
      <value>f</value>
    </node>
  </node>
</node>';

$dom = new DOMDocument;
$xsl = new XSLTProcessor;

$dom->loadxml($xsl_s);
$xsl->importStylesheet($dom);

$dom->loadxml($xml_s);
echo $xsl->transformToXML($dom);
see also: http://www.google.de/search?&q=xslt
seopower
Forum Newbie
Posts: 2
Joined: Mon Jul 09, 2007 2:58 am

Post by seopower »

I am novice in php and will Greatly appriciate ..... If any one can provide some code examples for DOM or simple xml.

I want to diaplay categories like it is being displayed on pricegrabber.com home page.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

The DOM documentation is pretty straight forward and provides a lot of examples. It feels like using the JavaScript DOM model.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

seopower wrote:I am novice in php and will Greatly appriciate ..... If any one can provide some code examples for DOM or simple xml.
Since I already gave you a working example of xsl(t) and as superdezign mentioned the documentation provides a lot of examples your statement -sorry to say so- translates to "I don't want to learn that stuff, please code my script" for me.
You cannot expect to accomplish a complex task in "no time" when you're new/unexperienced in all techniques involved.
Last edited by volka on Mon Jul 09, 2007 7:54 am, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

POW! Right in the kissah.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Just for the record: There's nothing wrong with beeing new/unexperienced, we all were at some point. But then you have to allow yourself the time to learn or the money to hire someone if the pressure is already on.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

volka wrote:Just for the record: There's nothing wrong with beeing new/unexperienced, we all were at some point. But then you have to allow yourself the time to learn or the money to hire someone if the pressure is already on.
... And put forth a decent effort. The first step to failure is to not try.
Post Reply