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 6741157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:41:29+00:00 2026-05-26T11:41:29+00:00

I want to read a XML hierarchy into a tree of in-memory objects. The

  • 0

I want to read a XML hierarchy into a tree of in-memory objects. The XML tree could have n-levels of children. I do not know the exact number. My in-memory objects have a children and parent property to be bound to a tree control.

How can I read xml file/string in a generic way into my in-memory objects when I do not know how the xml element tags are called/written exactly?

For example someone could provide me a xml structure of units where each unit has many units etc… so I know the xml tag is “unit” but it could be “module” too or anything else… it must work generic but I do not what to ask the user entering the xml element tag name like “unit”.

Is that possible at all what I want to achieve?

  • 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-26T11:41:30+00:00Added an answer on May 26, 2026 at 11:41 am

    Either way, you have to know the node name to parse the hierarchy at least you have to have a definition. IMHO, XElement is the only sort of generic XML parser around. For instance, you have a XML like this:

    <module name="core">
        <modules>
            <module name="xml">
                <modules>
                    <module name="reader" />
                    <module name="writer" />
                </modules>
            </module>
            <module name="json">
                <modules>
                    <module name="serializer" />
                    <module name="deserializer" />
                </modules>
            </module>
        </modules>
    </module>
    

    As I said earlier, you should have some definitions like the root node must the hierarchical element name and the children container must be root node name + s. This is one simple way that you can allow your users to specify any node names they wish but with some constraints.

    You may parse the XML using XElement like this:

    XElement xElement = XElement.Load(@"path\to\your\xml\file");
    string rootNodeName = xElement.Name.LocalName;
    IEnumerable<XElement> xElements = xElement.Descendants(rootNodeName + "s");
    

    And of course you can Linq the xElements and to parse the hierarchy you can recur to build your tree control.

    You may take a kick start on xElement with these links below:

    • http://www.dotnetperls.com/xelement
    • Java2s
    • http://www.joe-stevens.com/2010/01/08/linq-to-xml-tutorial/

    Hope this helped.

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

Sidebar

Related Questions

I have xml files I want to read in and store in the database.
I have a java code to read XML nodes, I want to add in
I want to read xml file which looks like the following ... I have
need help to read xml file. i have one xml file which i want
I want to read an XLSX file into XML and the pass this XML
I have the following XML file with page nodes which I want to read
I have an xml file, inside views folder and I want read it, before
Hi I want to read an XML document but it may have some of
I want to read a simple foxpro dbf file and convert it into xml
I want to read an xml file, apply a transform, then write to another

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.