By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

equivalent code?

P: n/a
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.MapPat h("DogData.xml"));
ds.ReadXml(HttpContext.Current.Server.MapPath("Dog Data.xml"));
return ds;

Thanks!
haiQ

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"haiQ" <ha**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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.MapPat h("DogData.xml"));
ds.ReadXml(HttpContext.Current.Server.MapPath("Dog Data.xml"));
return ds;

Thanks!
haiQ

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.