PDA

Click to See Complete Forum and Search --> : [2.0] loading config.xml file into XMLDocument object


bnathvbdotnet
Jun 20th, 2006, 07:07 PM
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);

jmcilhinney
Jun 20th, 2006, 07:25 PM
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?