Click here to Skip to main content
15,914,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi Guys.
I am trying to create a menu list with the sub items by reading a xml file. I can create ul and li tag in code behind by reading the xml file elements and loop through it and create a html string but, I want to is there any other best way to do this?
My XML file look like below:
<MenuControl>
  <Parent href="#" text="Parent1">
  </Parent>
  <Parent href="#" text="Parent2">
    <subMenu href="#" text="Sub Menu 1">
    </subMenu>
    <subMenu href="#" text="Sub Menu 2">
    </subMenu>
  </Parent>
  <Parent href="#" text="Parent3">
    <subMenu href="#" text="Sub Menu 1">
    </subMenu>
    <subMenu href="#" text="Sub Menu 2">
    </subMenu>
  </Parent>
  <Parent href="#" text="Parent4">
    <subMenu href="#" text="Sub Menu 1">
    </subMenu>
    <subMenu href="#" text="Sub Menu 2">
    </subMenu>
  </Parent>
  <Parent href="#" text="Parent5">
    <subMenu href="#" text="Sub Menu 1">
    </subMenu>
    <subMenu href="#" text="Sub Menu 2">
    </subMenu>
  </Parent>
  <Parent href="#" text="Parent6">
    <subMenu href="#" text="Sub Menu 1">
    </subMenu>
    <subMenu href="#" text="Sub Menu 2">
    </subMenu>
  </Parent>
  <Parent href="#" text="Parent7">
    <subMenu href="#" text="Sub Menu 1">
    </subMenu>
    <subMenu href="#" text="Sub Menu 2">
    </subMenu>
  </Parent>
</MenuControl>
My file HTML tag should be like the following:
<ul class="topMenu">
        <li><a href="#">Parent1</a></li>
        <li><a href="#">Parent2</a>
            <ul class="subMenu">
                <li><a href="#">Sub Menu 1</a></li>
                <li><a href="#">Sub Menu 2</a></li>
            </ul>
        </li>
        <li><a href="#">Parent3</a>
            <ul class="subMenu">
                <li><a href="#">Sub Menu 1</a></li>
                <li><a href="#">Sub Menu 2</a></li>
            </ul>
        </li>
        <li><a href="#">Parent4</a>
            <ul class="subMenu">
                <li><a href="#">Sub Menu 1</a></li>
                <li><a href="#">Sub Menu 2</a></li>
            </ul>
        </li>
        <li><a href="#">Parent5</a>
            <ul class="subMenu">
                <li><a href="#">Sub Menu 1</a></li>
                <li><a href="#">Sub Menu 2</a></li>
            </ul>
        </li>
        <li><a href="#">Parent6</a>
            <ul class="subMenu">
                <li><a href="#">Sub Menu 1</a></li>
                <li><a href="#">Sub Menu 2</a></li>
            </ul>
        </li>
        <li><a href="#">Parent7</a>
            <ul class="subMenu">
                <li><a href="#">Sub Menu 1</a></li>
                <li><a href="#">Sub Menu 2</a></li>
            </ul>
        </li>
    </ul>
Please provide me some suggestions to create these HTML tag in code behind.
Thanks in advance.
-Jaffer
Posted

1 solution

You can easily convert XML to HTML using XSLT.

See HERE[^] and you can find lots of information around for more info and samples on the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900