Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 788833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:25:46+00:00 2026-05-14T21:25:46+00:00

i have a table with hierarchical structure. like this: (source: aspalliance.com ) and table

  • 0

i have a table with hierarchical structure. like this:
alt text
(source: aspalliance.com)

and table data shown here:
alt text
(source: aspalliance.com)

this strategy gives me the ability to have unbounded categories and sub-categories.

i use ASP.net 3.5 SP1 and LINQ and MSSQL Server2005. How to convert it to XML? I can Do it with Dataset Object and “.GetXML()” method. but how to implement it with LINQtoSQL or LINQtoXML??? or if there is another simpler way to perform that? what is your suggestion? the best way? I searched the web but found nothing for .net 3.5 featuers.

Question Update
thnks to Murph but Now I have a New Problem. I want to Make a Dunamic SiteMap file in my Project. You Know the SiteMap file in ASP.net looks like this:

<siteMapNode url="~/Category?cid=0" title="Home"  description="Home">

    <siteMapNode url="~/Category?cid=1" title="a"  description="" />

    <siteMapNode url="~/Category?cid=2" title="b"  description="" >

        <siteMapNode url="~/Category?cid=3" title="c"  description="" />

        <siteMapNode url="~/Category?cid=4" title="d"  description="" />

    </siteMapNode>
</siteMapNode>

Main Problem is that according to Mr.Murph’s Code the sub categories will nested in element. but in SiteMap Case we have no such a elements and all of categories and sub categories are nested in elements. how can I change Mr.Murph code to shape this Schema?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:25:46+00:00Added an answer on May 14, 2026 at 9:25 pm

    Ok very quickly (and thoroughly untested).

    To “roll your own” XML using Linq to SQL and Linq to XML (which are generic .NET not ASP.NET specific) is fairly simple, this should be sufficient given a few assumptions which I’ll detail after (now modified slightly as suggested):

    void Main()
    {
        DataContext dc = new DataContext();
    
        menuXML = new XDocument();
        XElement root = new XElement("menuxml",
            from m in dc.Menus
            where m.ParentID == null
            select GetMenuXML(m));
    
        menuXML.Add(root);
        // You've now got an XML document that you can do with as you need
        // For test you can save...
        menuXML.Save("filename.xml");
    }
    
    private static XElement GetMenuXML(Menu menu) 
    { 
        return new XElement("category",  
            new XAttribute("MenuID", menu.MenuID), 
            new XAttribute("Text", menu.Text), 
            new XElement("Description", menu.Description), 
            new XElement("menus", menu.Menus.Select(m => GetMenuXML(m)))); 
    }
    

    Ok, from the top

    • I’m assuming a Linq to SQL data context called DataContext in which you’ve got the table mapped to Menus and that the parent/child relation is ChildMenus at the parent end.
    • We create a new document
    • We create a new element that we’ll use as the root that we’ll call menuxml
    • We then do a linq to SQL query to select all the menu entries that don’t have a parent and call GetMenuXML to output the XML for a single menu record (i.e that record and its children) for those entries.
    • GetMenuXML outputs a single menu entry split betwixt attributes and elements the only slightly different thing is that I’ve used a lamba expression instead of the verbose syntax for generating the child menus – but if I’ve got it right (remember no test!) thats doing something along the lines of

    from m in menu.ChildMenus select GetMenuXML(m)

    If it works (!) you should get XML something like

    <menuxml>
        <menu MenuID="1" Text="Product">
            <Description>A list of products</Description>
            <menus>
                <menu MenuID="6" Text="Background">
                    <Description>Product Background</Description>
                    <menus>
                        <menu MenuID="18" Text="Internet Restriction">
                            <Description>Internet Restriction</Description>
                            <!-- children if any would be here -->
                        </menu>
                        <menu MenuID="19" Text="Speed Solution">
                            <Description>Speed Solutions</Description>
                        </menu>
                    </menus>
                </menu>
                <menu MenuID="7" Text="Background">
                    <Description>Product Details</Description>
                </menu>
            </menus>
        </menu>
        <!-- rest of the top level menus -->
    </menuxml>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table containing hierarchical data. There are currently ~8 levels in this
I have a hierarchical class structure like this: Category -> Template -> Instance A
I have a hierarchical (tree structure) SQL Server table TEmployee with following columns Id
I have a hierarchical table on Oracle pl/sql. something like: create table hierarchical (
I have a hierarchical structure stored in a table. Each element has a pointer
I have some hierarchical data that I need display as a table, can I
I have a table with a structure like (id, parent_id) in Oracle11g. id parent_id
I have a table with data representing a tree structure, with one column indicating
I have a hierarchical data structure which, as far as I can see, needs
I have a table containing typical hierarchical data for tasks with an arbitrary level

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.