equivalent code?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm a new at C# - so please forgive my ignorance. The following 2 snippets
of code seem to be fairly equivalent. Is there any advantage to using 1 over
the other? Example 2 seems to be much more efficient...

Example 1:
XmlTextReader xtr = new
XmlTextReader(HttpContext.Current.Server.MapPath("DogData.xml"));

XmlDataDocument xdd = new XmlDataDocument();
DataSet ds = xdd.DataSet;
ds.ReadXmlSchema(xtr);
xtr.Close ();

xtr = new XmlTextReader(HttpContext.Current.Server.MapPath("DogData.xml"));
xdd.Load(xtr);
xtr.Close();
return ds;

Example 2:
DataSet ds = new DataSet();
ds.ReadXmlSchema(HttpContext.Current.Server.MapPath("DogData.xml"));
ds.ReadXml(HttpContext.Current.Server.MapPath("DogData.xml"));
return ds;

Thanks!
haiQ
 
Ex.2 is much simpler. I'd choose it.

In Ex.1 you create XmlDataDocument over DataSet and feed DataSet through it.

You may want to use XmlDataDocument to treat (access or edit) DataSet as XML
tree.

Sergey
 
Back
Top