-
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!
-
Re: dataset xml
You mean methods like DataSet.ReadXml() and DataSet.WriteXml()?
-
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!
-
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.
-
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
-
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>
-
Re: dataset xml
<NewDataSet>\n <Table>\n <Name>Afghanistan, UK</Name> \n</Table>
</NewDataSet>
thats what it looks like
-
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?
-
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?
-
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.