Results 1 to 5 of 5

Thread: XML and datasets

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    XML and datasets

    i have the following xml file:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <settings>
    	<wallpapers>
    		<Name>THREE_DIMENSIONAL</Name>
    		<Url>www.3d.com</Url>
    	</wallpapers>
    	<wallpapers>
    		<Name>MALES</Name>
    		<Url>www.males.com</Url>
    	</wallpapers>
    	<wallpapers>
    		<Name>FEMALES</Name>
    		<Url>www.females.com</Url>
    	</wallpapers>
    </settings>
    now i want to get for the URL for THREE_DIMENSIONAL..how do i do this thru a dataset? also, if the only way evolves changing the xml's format there is absolutily no problem

    thanks in advance
    \m/\m/

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    With a dataset you can use the select method to get a filtered set of datarows:
    VB Code:
    1. Dim ds As New DataSet()
    2.         ds.ReadXml("..\test.xml")
    3.         Dim dr() As DataRow = ds.Tables(0).Select("Name='THREE_DIMENSIONAL'")
    4.         If dr.Length > 0 Then
    5.             MsgBox(dr(0)("URL").ToString)
    6.         End If

    Or you can use a dataview:
    VB Code:
    1. Dim ds As New DataSet()
    2.         ds.ReadXml("..\test.xml")
    3.         Dim dv As New DataView(ds.Tables(0), "Name='THREE_DIMENSIONAL'", "Name", DataViewRowState.CurrentRows)
    4.         If dv.Table.Rows.Count > 0 Then
    5.             MsgBox(dv.Table.Rows(0)("URL").ToString)
    6.         End If

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    sorry to ask but whats the difference between the dataset and dataview?
    \m/\m/

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    A dataview is a filtered view of a dataset. Sort of like in SQL there are Tables and there are Views.

    Here is the samething using an XMLDocument instead:
    VB Code:
    1. Dim xDoc As New Xml.XmlDocument()
    2.         xDoc.Load("..\test.xml")
    3.         Dim xNode As Xml.XmlNode = xDoc.SelectSingleNode("/settings/wallpapers[Name=""THREE_DIMENSIONAL""]")
    4.         If Not xNode Is Nothing Then
    5.             MsgBox(xNode.ChildNodes(1).InnerText)
    6.         End If

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i used this and worked like a charm:
    VB Code:
    1. Dim ds As New DataSet()
    2.         ds.ReadXml("..\test.xml")
    3.         Dim dr() As DataRow = ds.Tables(0).Select("Name='THREE_DIMENSIONAL'")
    4.         If dr.Length > 0 Then
    5.             MsgBox(dr(0)("URL").ToString)
    6.         End If

    tks
    \m/\m/

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