Results 1 to 14 of 14

Thread: XML string to Dataset??

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    XML string to Dataset??

    I have a dataset. I get the XML rapresentation of that data with the method GetXML. Now i want to put it back to the dataset. How can I do? I know how to do this with an XML file...

    Thx,
    Xmas
    Learn, this is the Keyword...

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: XML string to Dataset??

    Originally posted by Xmas79
    I have a dataset. I get the XML rapresentation of that data with the method GetXML. Now i want to put it back to the dataset. How can I do? I know how to do this with an XML file...
    Thx,
    Xmas
    sorry , but do you want to write from dataset or to dataset , ?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    I want to fill a dataset. I know how to fill dataset starting from an XML file, but I want to know how to fill dataset starting from an XML string.
    Learn, this is the Keyword...

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. 'after open connection and stuff do this ...
    2. Dim ds As New DataSet()
    3. Dim xmlstr As String
    4. xmlstr = ds.GetXml()

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    I know this!!!!!! I want to do the reverse!!!!!!
    Learn, this is the Keyword...

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Dim ds As New DataSet()
    2. ds.ReadXml("....\myxml.xml")
    Is it this the reverse you're talking about ?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    No, it's like this:
    VB Code:
    1. Dim ds As New DataSet()
    2. Dim xmlstr As String
    3. ds.ReadXml(xmstr)
    Learn, this is the Keyword...

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Originally posted by pirate
    This is what you said before. I don't want this. It's similar, but I want to fill a dataset from an XML string, not from an XML file.
    Learn, this is the Keyword...

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Xmas79
    This is what you said before. I don't want this. It's similar, but I want to fill a dataset from an XML string, not from an XML file.
    It's commented.....
    Attached Files Attached Files

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    from the downloaded file:
    VB Code:
    1. Public ds As New DataSet()
    2.     Public str As String
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5. '***** 1ST PART *****
    6.         'fill data from XML File
    7.         ds.ReadXml("xml1.xml")
    8. '***** END 1ST PART *****
    9.  
    10. '***** 2ND PART *****
    11.         Dim dr As DataRow = ds.Tables(0).Rows(0)
    12.         'write XML content to textbox (you can store it to string
    13.         'variable type)
    14.         TextBox1.Text = dr.Item(0)
    15. '***** END 2ND PART *****
    16.  
    17. '***** 3RD PART *****
    18.         'this will store string value to dataset again
    19.         Dim dasave As DataRow = ds.Tables(0).NewRow()
    20.         dasave(0) = TextBox1.Text
    21.         ds.Tables(0).Rows.Add(dasave)
    22. '***** END 3RD PART *****
    23.  
    24.     End Sub

    1ST PART: Fill a DataSet reading from file. Not what I want.
    2ND PART: Takes a row from an already filled DataSet and put it into a textbox. Not what I want.
    3RD PART: Put back the textbox.text into an already structured, well formed DataSet. Not what I want.

    WHAT I WANT: Fill a new empty DataSet from a String. It means that I have a string that IS a dataset in XML form. I could save it to a file, and then read it with the 1ST PART method. But I don't want to save to file! Clear?
    Learn, this is the Keyword...

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Xmas79
    from the downloaded file:
    VB Code:
    1. Public ds As New DataSet()
    2.     Public str As String
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5. '***** 1ST PART *****
    6.         'fill data from XML File
    7.         ds.ReadXml("xml1.xml")
    8. '***** END 1ST PART *****
    9.  
    10. '***** 2ND PART *****
    11.         Dim dr As DataRow = ds.Tables(0).Rows(0)
    12.         'write XML content to textbox (you can store it to string
    13.         'variable type)
    14.         TextBox1.Text = dr.Item(0)
    15. '***** END 2ND PART *****
    16.  
    17. '***** 3RD PART *****
    18.         'this will store string value to dataset again
    19.         Dim dasave As DataRow = ds.Tables(0).NewRow()
    20.         dasave(0) = TextBox1.Text
    21.         ds.Tables(0).Rows.Add(dasave)
    22. '***** END 3RD PART *****
    23.  
    24.     End Sub

    1ST PART: Fill a DataSet reading from file. Not what I want.
    2ND PART: Takes a row from an already filled DataSet and put it into a textbox. Not what I want.
    3RD PART: Put back the textbox.text into an already structured, well formed DataSet. Not what I want.

    WHAT I WANT: Fill a new empty DataSet from a String. It means that I have a string that IS a dataset in XML form. I could save it to a file, and then read it with the 1ST PART method. But I don't want to save to file! Clear?
    this will do the job . either you're not understanding the post or the question :

    VB Code:
    1. Dim dr_save As DataRow = new_ds.Tables(0).NewRow()
    2.  Dim mystr = "blah blah"
    3. dr_save(0) = mystr
    4. ds.Tables(0).Rows.Add(dr_save)

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    To load xml as a string you can either use a derived XMlReader (i.e the XMLTextReader object) which for your situation may be more than is needed. You can also load the string into a memorystream and load it from there. Here is an example of the later:

    VB Code:
    1. 'syntax example
    2.     dim ds as Dataset=FillDatasetWithXML(myXMLString)
    3.  
    4.     Public Function FillDatasetWithXML(ByVal xml As String) As DataSet
    5.         Dim ds As New DataSet()
    6.         Dim ms As New IO.MemoryStream()
    7.         Dim sw As New IO.StreamWriter(ms)
    8.         'write cml to the stream
    9.         sw.Write(xml)
    10.         sw.Flush()
    11.         'position to the start of the stream
    12.         ms.Position = 0
    13.         'read the xml in to the dataset
    14.         ds.ReadXml(ms)
    15.         'clean up
    16.         sw.Close()
    17.         ms.Close()
    18.         Return ds
    19.     End Function

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    pirate: This will not do the job!!! Your code puts into a field of the DataSet the value contained in my string, but this isn't what I want! I want to get both structure and fields values of the DataSet from the string.

    Edneeis: This will do the job. I did it in the same way, but I used StringReader (I think... I'm too tired to remember, and I can't see the code because I've to reboot...) instead of memorystream...

    Thx you both,
    Xmas
    Learn, this is the Keyword...

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