Jump to content

XML with n numbers of nested categories


seopower

Recommended Posts

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?

 

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:

 

<taxonomy>
   <form id=1 name=category1>
   <taxonomy>
     <form id=2 name=subcategory1>
   </taxonomy>
   <form id=3 name=category2>
   <form id=4 name=category3>
</taxonomy>

Link to comment
Share on other sites

i dont know much about xml but from what you are saying wanting to have them linked could you do something like

 

<taxonomy>
   <form id=1 name=category1>
   <taxonomy>
     <form id=1 name=subcategory1>
     <form id=1 name=subcategory2>
     <form id=1 name=subcategory3>
     <form id=1 name=subcategory4>
   </taxonomy>
   <form id=3 name=category2>
   <form id=4 name=category3>
</taxonomy>

 

like i said i dont know much so i hope this helps

Link to comment
Share on other sites

i dont know much about xml but from what you are saying wanting to have them linked could you do something like

 

I want to know how will php loop (or any other method) will work to get data from xml in above mentioned format?

Link to comment
Share on other sites

First off you should NOT use singleton tags in xml - each tag should be opened AND closed.

 

xsl(t) is how the information is 'looped' and formated for display on a page.

 

now out of interest are these forms going to be html forms? if so you should NOT nest html forms. If that is indeed what you intended I suggest you alter you approach.

Link to comment
Share on other sites

ToonMariner is correct the xml should look like this:

<taxonomy>

  <form id="1" name="category1">

  <taxonomy>

    <form id="2" name="subcategory1">

</form>

  </taxonomy>

  </form>

  <form id="3" name="category2">

  </form>

  <form id="4" name="category3">

  </form>

</taxonomy>

Link to comment
Share on other sites

This is the actual 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>

 

and so one...by this you will have idea about categories and subcategories. Also I cant modify XML as its being provided by REST method from someone else.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.