|
-
Dec 16th, 2004, 09:21 AM
#1
Thread Starter
PowerPoster
dataset xml
hi
i was wondering, is there a way to convert a string dataset xml to a proper dataset in C#
the web service i am calling, gives me a string dataset back i.e:
<newdataset> <table>
etc...
how can i convert that to a dataset so i can get the values i need?
thanks!
-
Dec 16th, 2004, 09:52 AM
#2
Frenzied Member
Re: dataset xml
You mean methods like DataSet.ReadXml() and DataSet.WriteXml()?
-
Dec 16th, 2004, 09:54 AM
#3
Thread Starter
PowerPoster
Re: dataset xml
yeh, but i get errors. ok this is the code:
string theCountries = theNameWebService.GetCountries();
XmlTextReader xl = new XmlTextReader(this.theNameWebService.Url);
ds.ReadXml(xl);
i get an exception of a duplicate name at ds.ReadXml(xl); saying that the datatable "binding" name already exists :-/ i havent even made a datatable!
-
Dec 16th, 2004, 09:58 AM
#4
Frenzied Member
Re: dataset xml
I'd have to look at the xml, probably, to see what the problem is. Is the web service returning a DataSet type? Do you control the web service? If it is returning a DataSet, you can just grab the DataSet itself:
Code:
DataSet ds = Globals.wsMain.GetTable("vActiveOfficers");
In that example, Globals.wsMain.GetTable is a web service method that returns a DataSet.
-
Dec 16th, 2004, 09:59 AM
#5
Thread Starter
PowerPoster
Re: dataset xml
i dont control the web service, its a live webservice on the net somewhere...and returns me a string which looks like an xml dataset
-
Dec 16th, 2004, 10:05 AM
#6
Frenzied Member
Re: dataset xml
I wonder if it's really a DataSet, or just something that looks like one. Not sure how it would work if you try to use DataSet methods on something that doesn't conform.
What's the xml look like? Here's the beginning of a DataSet my web service returns
Code:
<?xml version="1.0" encoding="utf-8" ?>
- <DataSet xmlns="http://patriotdispatch.com/webservices/">
- <xs:schema id="dsUserTables" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="dsUserTables" msdata:IsDataSet="true">
- <xs:complexType>
- <xs:choice maxOccurs="unbounded">
- <xs:element name="Table">
- <xs:complexType>
-
Dec 16th, 2004, 10:08 AM
#7
Thread Starter
PowerPoster
Re: dataset xml
<NewDataSet>\n <Table>\n <Name>Afghanistan, UK</Name> \n</Table>
</NewDataSet>
thats what it looks like
-
Dec 16th, 2004, 10:12 AM
#8
Frenzied Member
Re: dataset xml
Well, just guessing here, but I guess if the built in DataSet methods don't like the xml, it's not gonna work that way. Maybe you have to do it the hard way, parse the xml and build the DataSet manually?
-
Dec 16th, 2004, 11:29 AM
#9
Thread Starter
PowerPoster
Re: dataset xml
well, i took the dataset, wrote it to a file, told the dataset to read it, resave it then reloaded it
great 
but now, how do i go through each element in the dataset (which read the xml file) and read out the values?
-
Dec 16th, 2004, 11:39 AM
#10
Frenzied Member
Re: dataset xml
Glad you got it working. If you want to iterate through the DataSet, use a foreach loop. You can have multiple tables, which has multiple columns, rows, etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|