Results 1 to 10 of 10

Thread: dataset xml

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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!

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: dataset xml

    You mean methods like DataSet.ReadXml() and DataSet.WriteXml()?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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!

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    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.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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

  6. #6
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    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>

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: dataset xml

    <NewDataSet>\n <Table>\n <Name>Afghanistan, UK</Name> \n</Table>


    </NewDataSet>


    thats what it looks like

  8. #8
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    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?

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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?

  10. #10
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    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
  •  



Click Here to Expand Forum to Full Width