Using strings to create XML is a HORRIBLE PRACTICE:
Here is some code:
private DataSet GetDataSet1()
{
DataSet ds = new DataSet();
System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
sb.Append("<?xm l version=\"1.0\" ?><items>");
sb.Append("<ite m>");
sb.Append("<key >abc</key>");
sb.Append("<val ue>Apple Berry Cat</value>");
sb.Append("<tim e>" + DateTime.Now.To LongTimeString( ) + "</time>");
sb.Append("</item>");
sb.Append("<ite m>");
sb.Append("<key >def</key>");
sb.Append("<val ue>Dough Elephant Fence</value>");
sb.Append("<tim e>" + DateTime.Now.To LongTimeString( ) + "</time>");
sb.Append("</item>");
sb.Append("<ite m>");
sb.Append("<key >hij</key>");
sb.Append("<val ue>House Igloo Jumprope</value>");
sb.Append("<tim e>" + DateTime.Now.To LongTimeString( ) + "</time>");
sb.Append("</item>");
sb.Append("</items>");
System.IO.Memor yStream ms = new System.IO.Memor yStream();
System.IO.Strea mWriter writer = new System.IO.Strea mWriter(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******** *************** ***********@j22 g2000hsf.google groups.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(da ta);
DataSet ds = new DataSet();
ds.ReadXml(data ); //This is where the program fails.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I am using Framework 1.1 still (if that helps.)