473,748 Members | 6,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert XML Stream to DataSet

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.)
Jun 27 '08 #1
4 9436
The error message I get is:

An unhandled exception of type 'System.Argumen tException' occurred in
system.windows. forms.dll

Additional information: The same table (link) cannot be the child
table in two nexted relations.
Jun 27 '08 #2

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.)

Jun 27 '08 #3
Argument Null helps a lot!

Be sure to initialize your objects:

Stream data = new Stream(); // Stream may take parameters
data = client.OpenRead (url);

Then, keep going!

"Brad" wrote:
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.)
Jun 27 '08 #4
I believe the error is occurring because you have more than one containing
xml nodes in the XML that have the same name. the DataSet is trying to figure
out which nodes should become datatables, and that's why its failing. you
could try some of the overloads "fragment", "inferschem a" etc.

Otherwise, you are going to have to fix up your xml. By the way, you can
load the xml directly into the DataSet by passing the url into the ReadXml
method. There is no need for the WebClient code.
-- Peter
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net
"Brad" wrote:
The error message I get is:

An unhandled exception of type 'System.Argumen tException' occurred in
system.windows. forms.dll

Additional information: The same table (link) cannot be the child
table in two nexted relations.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
52687
by: jk | last post by:
I'm having trouble converting a datatable into xml, with resonse.write to aspx. I'm basically converting vb code that saved a recordset into a stream into c#, but the format is wrong. I've tried using streams, datadoc, xmlreader, etc with no success. I need to convert it directly to a string or via a stream, but not in a file. Here's some sample code that gives me the bad format. I'll post the good format below that give me rowsets rather...
7
7119
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done without strtol or s/printf function. Thanks, whatluo.
0
10265
by: Thaddeus | last post by:
//Author: //Thaddeus Jacobs, MCP //Kinematic Automation, Inc. //mailto:tjacobs@kinematic.com // //Description: //convert ADO .NET dataset to ADO 2.5 2.6 2.7 recordset and v/v //DataSet to recordset conversion. //Get RecordSet from Dataset //ds2rs DataSet2RecordSet
5
12688
by: ad | last post by:
I want to uplad a dataset to server by WebService, But the dataset is to huge (50 fields in 50000 rows) I want to compress it before upload, Now my steps are In Client 1. DataSet1.WriteXml("c:\my.xml") 2. Zip c:\my.xml to my.zip 3. Delete my.xml 4. Reade my.zip into FileSteam 5. Write the FileStream to Byte
1
2065
by: SL | last post by:
Hi - I'm fairly new to manipulating xml and I have an excel workbook and on one of the sheets is apparently a listobject... using it's xmlmap.export function I get an xml file that looks like this (truncated of course, you get the idea): <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns1:TransactionDetails xmlns:ns1="urn:Microsoft.IT.LicensePosition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns1:Trans> ...
4
9962
by: Fresh_Air_Rider | last post by:
Hi In the "good old" Classic ASP days, I used to stream records from a SQL Server database out to the user's browser in CSV format by using a combination of COALESCE and the ADODB.Stream object. The trouble is that I'm not really sure how to do this in C# 2005. This was a very useful technique and if anyone could please show me how to adapt the Classic ASP code to C# 2005, I'd be very grateful indeed.
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
1850
by: velmani | last post by:
hi , i have problem with Retrieving image from DB i have a table with image datatype i store a file by using code as follows -------------------------------------------------- string strType; int intLength,intStatus; Stream ipStream; intLength = File1.PostedFile.ContentLength; strType = File1.PostedFile.ContentType;
0
2877
by: =?Utf-8?B?cm9uZSBtYXRpYXM=?= | last post by:
I have the same task to do but everytime I tried to parse my code I get a null value returned after executing "dtMaterials.WriteXml(swMaterials);". I am using the following code: Hope you can hep me out with this. Thanks. DataTable dtMaterials = new DataTable(); StringWriter swMaterials = new StringWriter(); swMaterials = null; string strMaterials = string.Empty;
0
8831
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
9374
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
9325
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
8244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
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...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.