473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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

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
4 1774
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Marcin Kaliciński | last post by:
Hi, I've been looking for some time for a fileless C++ environment. I mean the environment where you don't store the program in cpp/h files, but instead you work with the C++ entities...
2
by: Jason Hirst | last post by:
Hi, I'm not sure if this is possible, I can't see why, but is there a way round a problem I have. I'm returning the results from a stored procedure, of which there could be anything from 5 to...
3
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. ...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
16
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill...
1
by: hzgt9b | last post by:
(FYI, using VB .NET 2003) Can someone help me with this... I'm trying to read in an XML file... it appears to work in that the DataSet ReadXML method dose not fail and then I am able to access the...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
3
by: Brad | last post by:
I'm having a problem reading data from an Excel file into a dataset. Can anybody give me an idea of what's happening? I've included the problematic source and the error message to the end of this...
8
by: T Driver | last post by:
Anyone have any idea how I can do the following? I have a connection to an XML file on a site I do not control, getting a string representation of the xml data that I can then feed to my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.