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

Reading a Dataset from an XML file - want a fileless solution

P: n/a
Here's a snippet of code I have:
==============================================
DataSet ds = new DataSet();

string strXMLFileName = Path.GetTempFileName();

StreamWriter sw = File.AppendText( strXMLFileName );
sw.WriteLine(@"<?xml version='1.0'?>");
sw.WriteLine(@"<Results>");

ServiceReply SearchResultData = CategoryWebService.EndRetrieveStateData(
iaCategoryHandle );
sw.WriteLine( SearchResultData.CategoryXML[ 0 ] );

sw.WriteLine(@"</Results>");
sw.Close();

ds.ReadXml( strXMLFileName );
==============================================

"SearchResultData.CategoryXML[ 0 ]" is some XML returned from a web
service. I want to take this XML, prepend it with the 2 lines and
append the last line and then convert it into a dataaset object. But, I
don't want to use a file if possible.

How can get I accomplish what is being done above without the use of the
file?

-BEP
Apr 26 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
What you might try is to deserialize your
SearchResultData.CategoryXML[0] back into an object and adding it (and
any successive search results if needed) to a collection object/an
array used to feed the dataset (be it one-at-a-time or after
re-serializing the collection to XML)

HTH,
Chris

Apr 26 '06 #2

P: n/a
DataSet ds = new DataSet();
StringBuilder sb = new StringBuilder();
sb.Append(@"<?xml version='1.0'?>");
sb.Append(@"<Results>");
ServiceReply SearchResultData = CategoryWebService.EndRetrieveStateData(
iaCategoryHandle );
sb.Append( SearchResultData.CategoryXML[ 0 ] );
sb.Append(@"</Results>");
byte[] b = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
MemoryStream ms = new MemoryStream(b);
ds.ReadXml( ms);
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brian Parker" wrote:
Here's a snippet of code I have:
==============================================
DataSet ds = new DataSet();

string strXMLFileName = Path.GetTempFileName();

StreamWriter sw = File.AppendText( strXMLFileName );
sw.WriteLine(@"<?xml version='1.0'?>");
sw.WriteLine(@"<Results>");

ServiceReply SearchResultData = CategoryWebService.EndRetrieveStateData(
iaCategoryHandle );
sw.WriteLine( SearchResultData.CategoryXML[ 0 ] );

sw.WriteLine(@"</Results>");
sw.Close();

ds.ReadXml( strXMLFileName );
==============================================

"SearchResultData.CategoryXML[ 0 ]" is some XML returned from a web
service. I want to take this XML, prepend it with the 2 lines and
append the last line and then convert it into a dataaset object. But, I
don't want to use a file if possible.

How can get I accomplish what is being done above without the use of the
file?

-BEP

Apr 26 '06 #3

P: n/a
I don't know if this helps or not.

C#


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;
}

VB.NET
Private Function GetDataSet1() As DataSet
Dim ds As New DataSet

Dim sb As New System.Text.StringBuilder
sb.Append("<?xml version=""1.0""?><items>")

sb.Append("<itemid>20002</itemid>")
sb.Append("<friendlyname1>Macintosh</friendlyname1>")
sb.Append("<friendlyname2>MA</friendlyname2>")
sb.Append(("<time>" + DateTime.Now.ToLongTimeString() + "</time>"))
sb.Append("<parentid>2001</parentid>")
sb.Append("</item>")

sb.Append("</items>")

Dim ms As New System.IO.MemoryStream
Dim writer As New System.IO.StreamWriter(ms)
writer.Write(sb.ToString())
writer.Flush()
ms.Position = 0
ds.ReadXml(ms)
Return ds
End Function 'GetDataSet1
"Brian Parker" <be******@yahoo.com> wrote in message
news:WoL3g.4056$B42.902@dukeread05...
Here's a snippet of code I have:
==============================================
DataSet ds = new DataSet();

string strXMLFileName = Path.GetTempFileName();

StreamWriter sw = File.AppendText( strXMLFileName );
sw.WriteLine(@"<?xml version='1.0'?>");
sw.WriteLine(@"<Results>");

ServiceReply SearchResultData = CategoryWebService.EndRetrieveStateData(
iaCategoryHandle );
sw.WriteLine( SearchResultData.CategoryXML[ 0 ] );

sw.WriteLine(@"</Results>");
sw.Close();

ds.ReadXml( strXMLFileName );
==============================================

"SearchResultData.CategoryXML[ 0 ]" is some XML returned from a web
service. I want to take this XML, prepend it with the 2 lines and
append the last line and then convert it into a dataaset object. But, I
don't want to use a file if possible.

How can get I accomplish what is being done above without the use of the
file?

-BEP

Apr 26 '06 #4

P: n/a
sloan wrote:
I don't know if this helps or not.
private DataSet GetDataSet1()
{
DataSet ds = new DataSet();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<?xml version=\"1.0\"?><items>"); ** STUFF SNIPPED ** 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 think that's exactly what I need.
Thanks,
-BEP
Apr 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.