Results 1 to 2 of 2

Thread: [2.0] loading config.xml file into XMLDocument object

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    [2.0] loading config.xml file into XMLDocument object

    Task:
    load an xml document into XMLDocument object.

    XMLDocument xmldoc;
    xmldoc.Load(xrdr);

    This task can be done one step (as shown above) but the books & experienced programmer at work does that task in 4 different steps: curious to know opinion of other c# programmers.

    FileStream input; // maintains connection to a file
    StreamReader fileStreamReader; // reads data from a text file
    XmlTextReader xrdr;
    XmlDocument xmldoc;

    //Create a filestream to get the read access to the file

    input = new FileStream(StartUpPath, FileMode.Open, FileAccess.Read);


    fileStreamReader = new StreamReader(input);


    xrdr = new XmlTextReader(fileStreamReader);

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] loading config.xml file into XMLDocument object

    You can open an XML file in one line by passing the path of the file to the XmlDocument.Load method. That's very simple code but it doesn't mean that it's the most efficient. It may be that if you were to write a few more lines of code the actual process would execute less MSIL. That would make your application more efficient, but by such a small amount it would be completely insignificant. Unless you know that writing more code will make your app more efficient then write the least code you can to make your purpose clear. Even if you can make your app more efficient, is it worth loading an XML file a few nanoseconds faster and then wait for a couple of seconds while the user gets into gear and does something with the result?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width