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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:44:33+00:00 2026-05-25T12:44:33+00:00

This code is programmed to display some data values from alot of xml files

  • 0

This code is programmed to display some data values from alot of xml files is their anyway to alter it so that it write the values to a dataset/table?

    static void Main(string[] args)
    {
        string[] fileEntries = Directory.GetFiles(@"c:\Sciclone UAC", "*.cfg*");
        foreach (string fileName in fileEntries)
        {
            XDocument doc = XDocument.Load(fileName);
            var query = from x in doc.Descendants("XAxisCalib")
                        select new
                       {
                            //Max1 = x.Attribute("Max").Value,
                            //Min2 = x.Attribute("Min").Value


                            MaxChild = x.Descendants("Max"),
                            MinChild = x.Descendants("Min")
                        };

            foreach (var x in query)
            {
                foreach (var nextLevel in x.MaxChild)
                {
                    Console.WriteLine("XMax: " + nextLevel.Value);
                }
                foreach (var nextLevel in x.MinChild)
                {
                    Console.WriteLine("XMin: " + nextLevel.Value);
                }
                //Console.WriteLine("XAxisCalib");
            }



            var query2 = from y in doc.Descendants("YAxisCalib")

                         select new
                         {

                             //Max3 = x.Attribute("Max").Value,

                             //Min4 = x.Attribute("Min").Value

                             MaxChild = y.Descendants("Max"),
                             MinChild = y.Descendants("Min")

                         };


            foreach (var y in query2)
            {
                foreach (var nextLevel in y.MaxChild)
                {
                    Console.WriteLine("YMax: " + nextLevel.Value);
                }
                foreach (var nextLevel in y.MinChild)
                {
                    Console.WriteLine("YMin: " + nextLevel.Value);
                }

                //Console.WriteLine("YAxisCalib");



                var query3 = from z in doc.Descendants("ZAxisCalib")

                             select new
                             {

                                 //Max5 = x.Attribute("Max").Value,

                                 //Min6 = x.Attribute("Min").Value

                                 MaxChild = z.Descendants("Max"),
                                 MinChild = z.Descendants("Min")
                             };

                foreach (var z in query3)
                {
                    foreach (var nextLevel in z.MaxChild)
                    {
                        Console.WriteLine("ZMax: " + nextLevel.Value);
                    }
                    foreach (var nextLevel in z.MinChild)
                    {
                        Console.WriteLine("ZMin: " + nextLevel.Value);
                    }

                    //Console.WriteLine("ZAxisCalib");

                }

            }

        }
    }
}

}

  • 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-25T12:44:33+00:00Added an answer on May 25, 2026 at 12:44 pm

    I don’t know if I’m missing something, but what about the DataSet.ReadXml method?:

    DataSet ds = new DataSet();
    ds.ReadXml("myxmlfile.xml");              
    

    The ReadXml() method has an overload for passing in XmlReadMode, which provides various options handling the schema.

    In your case, assuming that you want to read each XML file into it’s own DataSet, you can do something like this:

    string[] fileEntries = Directory.GetFiles(@"c:\Sciclone UAC", "*.cfg*"); 
    foreach (string fileName in fileEntries) 
    { 
        DataSet ds = new DataSet();
        ds.ReadXml(fileName, XmlReadMode.InferSchema);
    }
    

    To read the XML files into the same DataSet, you can do something like this:

    DataSet masterSet = new DataSet();
    
    string[] fileEntries = Directory.GetFiles(@"c:\Sciclone UAC", "*.cfg*"); 
    foreach (string fileName in fileEntries) 
    { 
        //initialize a new dataset and read the xml into it
        DataSet tempSet = new DataSet();
        tempSet.ReadXml(fileName, XmlReadMode.InferSchema);
    
        //merge the tables from the temporary datset into the master dataset
        foreach (DataTable table in tempSet.Tables)
            masterSet.Merge(table);        
    }
    

    Here’s another way of doing the same thing, using the enumerable LINQ methods:

    DataSet masterSet = new DataSet();
    
    string[] fileEntries = Directory.GetFiles(@"c:\Sciclone UAC", "*.cfg*"); 
    foreach (string fileName in fileEntries) 
    { 
        //initialize a new dataset and read the xml into it
        DataSet tempSet = new DataSet();
        tempSet.ReadXml(fileName, XmlReadMode.InferSchema);
    
        //merge the tables from the temporary datset into the master dataset
        tempSet.Tables.Cast<DataTable>().ToList().ForEach(table => masterSet.Merge(table));  
    }
    

    One of the XmlReadMode enumerations should definitely suit your needs.

    • Auto
    • DiffGram
    • Fragment
    • IgnoreSchema
    • InferSchema
    • InferTypedSchema
    • ReadSchema

    Here is a link on MSDN that explains what the different XmlReadMode enumerations do:
    http://msdn.microsoft.com/en-us/library/system.data.xmlreadmode.aspx

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

Sidebar

Related Questions

Many beginning programmers write code like this: sub copy_file ($$) { my $from =
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
This code in JS gives me a popup saying i think null is a
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a
This code always works, even in different browsers: function fooCheck() { alert(internalFoo()); // We
This code does not seem to compile, I just need to write something to
This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
This code is executed by many way. When it's executed by the form button
This code leads to undefined behavior: void some_func() { goto undefined; { T x

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.