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

  • SEARCH
  • Home
  • 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 909771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:56:10+00:00 2026-05-15T16:56:10+00:00

I want to create dynamic XML hieararchy but still couldn’t be successful about it.I

  • 0

I want to create dynamic XML hieararchy but still couldn’t be successful about it.I tried LinqToXml classes and XML classes but still i couldn’t. I want to create such a hierarchy in a loop dynamically.

Create root node

<Root></Root>

Then add child for it.

<Root>
 <Biggest></Biggest>
</Root>

Then add child for last added node

<Root>
   <Biggest>
      <Bigger>
      </Bigger>
   </Biggest>
</Root>

Then go back add another

<Root>
   <Biggest>
      <Bigger>
      </Bigger>
      <Another>
      </Another>
  </Biggest>
</Root>

Edit: i want to give an example.

  XElement root = new XElement("root");
    XElement first = new XElement("first", "value");
    XElement second = new XElement("second", "Value");

    root.Add(first);
    //now how can add second node into first ??
    //I don't want to add second one into first then add it into root.
  • 1 1 Answer
  • 0 Views
  • 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-15T16:56:11+00:00Added an answer on May 15, 2026 at 4:56 pm

    You can create xml structure directly:

    XElement root = new XElement("root",
        new XElement("first", "value",
            new XElement("second", "Value")));
    

    Traverse the nodes using various methods like Element:

    root.Element("first").Element("second").Add(new XElement("third", "Value"));
    //or
    root.Descendants("second").First().Add(new XElement("underTheThird", "Value"));
    

    Add to any element:

    root.Add(new XElement("underTheSecond", 456));
    

    etc.

    Microsoft has several documents available for reading – like the Reference (LINQ to XML).

    Edit – collected the info I’ve posted in comments:

    You can do root.Add(first); first and then do first.Add(second);. The order in which you do that does not matter. The Xml document is not built like a string, it is a hierarchy of objects – you can add new nodes anywhere in the tree.

    Add uses an object as a parameter (same as the element constructor). You can add any XObject (that is possible to add) and any other object convertable to an XText (string, numbers, … – primarily using XmlConvert).

    Freshblood: I think that XmlLinkedNode class provide what i need.:
    You can use either the NextNode or the PreviousNode property to get the siblings and the Parent property to get the parent of the current node.

    Although all that info is reachable through the link I have posted in my answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create XML with dynamic Element and attribute according to Database record
I want to create a dynamic (fetching data from the database) XML sitemap which
I want to create a dynamic number of ImageViews in Android. But to display
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want to create dynamic tabPages in TabControl. In each tabPage I create dataGridView
I want to create dynamic number of thread which is depends on the database
Here is the problem details: 1) I want to create dynamic (ip based) download
I want to create a dynamic HTML5 canvas animation. This animation should use server
I want to create a Dynamic aspx Page in current solution through code-behind..forexample i
I want to create a dynamic Expression<Func<T,Y>> . Here is the code which works

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.