473,748 Members | 10,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetTempFil eName();

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

ServiceReply SearchResultDat a = CategoryWebServ ice.EndRetrieve StateData(
iaCategoryHandl e );
sw.WriteLine( SearchResultDat a.CategoryXML[ 0 ] );

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

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

"SearchResultDa ta.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 1798
What you might try is to deserialize your
SearchResultDat a.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(@"<?x ml version='1.0'?> ");
sb.Append(@"<Re sults>");
ServiceReply SearchResultDat a = CategoryWebServ ice.EndRetrieve StateData(
iaCategoryHandl e );
sb.Append( SearchResultDat a.CategoryXML[ 0 ] );
sb.Append(@"</Results>");
byte[] b = System.Text.Enc oding.UTF8.GetB ytes(sb.ToStrin g());
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.GetTempFil eName();

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

ServiceReply SearchResultDat a = CategoryWebServ ice.EndRetrieve StateData(
iaCategoryHandl e );
sw.WriteLine( SearchResultDat a.CategoryXML[ 0 ] );

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

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

"SearchResultDa ta.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.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;
}

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

Dim sb As New System.Text.Str ingBuilder
sb.Append("<?xm l version=""1.0"" ?><items>")

sb.Append("<ite mid>20002</itemid>")
sb.Append("<fri endlyname1>Maci ntosh</friendlyname1>" )
sb.Append("<fri endlyname2>MA</friendlyname2>" )
sb.Append(("<ti me>" + DateTime.Now.To LongTimeString( ) + "</time>"))
sb.Append("<par entid>2001</parentid>")
sb.Append("</item>")

sb.Append("</items>")

Dim ms As New System.IO.Memor yStream
Dim writer As New System.IO.Strea mWriter(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@dukere ad05...
Here's a snippet of code I have:
=============== =============== =============== =
DataSet ds = new DataSet();

string strXMLFileName = Path.GetTempFil eName();

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

ServiceReply SearchResultDat a = CategoryWebServ ice.EndRetrieve StateData(
iaCategoryHandl e );
sw.WriteLine( SearchResultDat a.CategoryXML[ 0 ] );

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

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

"SearchResultDa ta.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.Str ingBuilder sb = new System.Text.Str ingBuilder();
sb.Append("<?xm l version=\"1.0\" ?><items>"); ** STUFF SNIPPED ** 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 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
1729
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 itselves(classes, functions, namespaces etc.). Have you heard of anything like that working somewhere? Marcin
2
2856
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 1000 records. The results have simply 3 columns (parent, level, name), although this could increase in time to show more information. I also have a treeview, of which I'd like to bind this data to, and I've
3
4608
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. I'm getting some strange results depending the input XML file I use. I was wondering if somebody could help me understand what is going on or point me to a good reference. The code for my program looks like this:
3
9393
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 outs with datasets and datatables (and navigating through the filled datatable)... Just when I thought I had gotten the hang of it, another problem arose: I can't seem to access the "xsi:type" attribute. That is, the XML file looks
16
2485
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 it with incremental values e.g. if the tables looks like this: 23 56
1
2186
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 table names that are in the XML file, but I'm not able to access the rows. Here's the code that I've got - it assumes that the fileName passed in already exists: Public Sub GetInput(ByVal fileName As String) dsFileCopy = New...
4
12808
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 to read text file but could not get the data in correct format. All columns are not coming in dataset and rows are messing up. Suggestions please ???
3
8028
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 message. TIA Brad Here's a snippet of my source code:
8
3755
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 XmlDataSource object (CurrentXMLData): Stream newStream = myWebClient.OpenRead(myStringWebResource); TextReader newReader = new StreamReader(newStream); string newData = newReader.ReadToEnd(); CurrentXMLData.Data = newData;
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6795
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.