Using strings to create XML is a HORRIBLE PRACTICE:
Here is some code:
private DataSet GetDataSet1()
{
DataSet ds = new DataSet();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<?xml version=\"1.0\"?><items>");
sb.Append("<item>");
sb.Append("<key>abc</key>");
sb.Append("<value>Apple Berry Cat</value>");
sb.Append("<time>" + DateTime.Now.ToLongTimeString() + "</time>");
sb.Append("</item>");
sb.Append("<item>");
sb.Append("<key>def</key>");
sb.Append("<value>Dough Elephant Fence</value>");
sb.Append("<time>" + DateTime.Now.ToLongTimeString() + "</time>");
sb.Append("</item>");
sb.Append("<item>");
sb.Append("<key>hij</key>");
sb.Append("<value>House Igloo Jumprope</value>");
sb.Append("<time>" + DateTime.Now.ToLongTimeString() + "</time>");
sb.Append("</item>");
sb.Append("</items>");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(ms);
writer.Write(sb.ToString());
writer.Flush();
ms.Position = 0;
ds.ReadXml(ms);
return ds;
}
I use this for some light testing, but NEVER FOR REAL/PRODUCTION CODE.
Buyer beware.
"Brad" <mi******@gmail.comwrote in message
news:39**********************************@j22g2000 hsf.googlegroups.com...
>I am trying to convert an XML Stream received from a web api call into
a DataSet to use in the rest of the app. The issue I am running into
is that it will not convert the stream to a dataset and halts the
program.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
WebClient client = new WebClient();
string url="<url of the api>";
Stream data = client.OpenRead(url);
StreamReader reader = new StreamReader(data);
DataSet ds = new DataSet();
ds.ReadXml(data); //This is where the program fails.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I am using Framework 1.1 still (if that helps.)