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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:50:12+00:00 2026-05-24T23:50:12+00:00

I have set of XML’s ( varies between 2 and 6) that needs to

  • 0

I have set of XML’s ( varies between 2 and 6) that needs to be processed(traversed and checked for certain data and relations within) – The XML’s have some “Recursive Data”
here is a simple example involving a test data for explanation – 2 files considered as example

      File1.xml:
<some root------standard header not entered for the example----->
<parent>
    <ID>AB-1234</ID>
    <Description>Good book</Description>
    <Date_Created>08-10-2011</Date_Created>
    <child>
          <ID>BC-0001</ID>
          <Description>Nice</Description>
     </child>
</parent>
<parent>
    <ID>BC-0001</ID>
    <Description>Work Together</Description>
    <Date_Created>08-10-2011</Date_Created>
    <child>
          <ID>DC-0011</ID>
          <Description>Happy</Description>
     </child>
</parent>

  File2.xml:
<some root------standard header not entered for the example----->
<parent>
    <ID>DC-0011</ID>
    <Description> book</Description>
    <Date_Created>08-10-2011</Date_Created>
    <child>
          <ID>EF-0001</ID>
          <Description>Nice</Description>
     </child>
  </parent>
  <parent>
    <ID>EF-0001</ID>
    <Description>Work Together</Description>
    <Date_Created>08-10-2011</Date_Created>
    <child>
          <ID>PQ-0011</ID>
          <Description>Happy</Description>
     </child>
  </parent>

code I am using involves 1) loading both the XML files and combining them

  XDocument test1doc = XDocument.Load(@"d:\File1.xml");
  XDocument test2doc = XDocument.Load(@"d:\File2.xml");
  IEnumerable<XElement> testElist1 = test1doc.decendants("parent");
  IEnumerable<XElement> testElist2 = test2doc.decendants("parent");
  IEnumerable<XElement> testElistcombo = testElist1.union(testElist2);

2) use the testElistcombo to navigate the elements using foreach – 2 foreach loops (one for the parent and second for the child)
3) while traversing use an if condition to check whether parent ID and Child ID are equal.
I am able to build the hierarchy – no problem with that.
I was able to print the hierarchy along with the level value of the hierarchy.by including a counter in each of the foreach loops.
my output looks like

  AB-1234[level-0]
     >>BC-0001[level-1]
         >>DC-0011[level-3] 
                ..... and so on.

as i said no problem with that. –

Following is the area where i would like some help:
1) when the number of files increases to more than 2 to a max 6, i am using a union in the following manner

           XDocument test1doc = XDocument.Load(@"d:\File1.xml");
           XDocument test2doc = XDocument.Load(@"d:\File2.xml");
           XDocument test3doc = XDocument.Load(@"d:\File3.xml");
           XDocument test4doc = XDocument.Load(@"d:\File4.xml");
           XDocument test5doc = XDocument.Load(@"d:\File5.xml");
           XDocument test6doc = XDocument.Load(@"d:\File6.xml");
           IEnumerable<XElement> testElist1 = test1doc.decendants("parent");
           IEnumerable<XElement> testElist2 = test2doc.decendants("parent");
           IEnumerable<XElement> testElist3 = test3doc.decendants("parent");
           IEnumerable<XElement> testElist4 = test4doc.decendants("parent");
           IEnumerable<XElement> testElist5 = test5doc.decendants("parent");
           IEnumerable<XElement> testElist6 = test6doc.decendants("parent");

           IEnumerable<XElement> testElistcombo1 = testElist1.union(testElist2);
           IEnumerable<XElement> testElistcombo2 = testElistcombo1.union(testElist3);
           IEnumerable<XElement> testElistcombo3 = testElistcombo2.union(testElist4);
           IEnumerable<XElement> testElistcombo4 = testElistcombo3.union(testElist5);
           IEnumerable<XElement> testElistcombo5 = testElistcombo4.union(testElist6);

and use the testElistcombo5.for processing.
help required: an alternative way to load and combine the XML’s to for processing.

2) The process is resource intensive and take a fair bit of time to complete the hierarchy building
help required: is there an alternative way to process the xml’s for building hierarchy in Recursive Data.

  • 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-24T23:50:12+00:00Added an answer on May 24, 2026 at 11:50 pm

    Question 1: you can do this using the Enumerable.Aggregate function to aggregate the elements for each document into one set of elements:

    IEnumerable<string> filenames = { "filename1.xml", "filename2.xml" };
    
    IEnumerable<XDocument> documents = filenames.Select(XDocument.Load);
    IEnumerable<IEnumerable<XElement>> documentsElements = documents.Select(document => document.Descendants("parent"));
    IEnumerable<XElement> elements = documentsElements.Aggregate((working, next) => working.Union(next));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that serializes a set of objects (using XML serialization) that
I have a set of XML documents that all share the same schema. (They're
I have a set of XML files that I am processing with an XSL
I have set up a WCF service that will accept both JSON and XML
I have a file which is an XML representation of some data that is
In my tableview i have set xml data to display but until scroll it
I have created a data table using disconnected class, also created the data set,xml
I have set up multiple targets in a single xml file. I expect all
I have set the two buttons in preference.xml file. I want to go to
I have the following XML message: DECLARE @XML AS XML SET @XML = '<Message>

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.