Problem accessing complex XML child node when using Dataset

Discussion in 'ASP .Net' started by N. Demos, Jun 9, 2005.

  1. N. Demos

    N. Demos Guest

    Hello,
    I'm having problems accessing a complex XML child node (latitude &
    longitude), and passing it to a function when the XML file has been read
    into a DataSet. Specifically, the returned object from accessing the
    'latitude' and 'longitude' nodes is not a DataTable (as specified in the
    MSDN). I'm not sure what type is being returned, nor how to go about
    finding out. Any pointers would be appreciated. Below is the relevent
    Error message, XML, and VB code. Thanks for your time and attention.

    Regards,
    N. Demos


    Error Msg:
    ------------
    Exception Details: System.InvalidCastException: Specified cast is not valid.


    XML:
    --------
    <cities>
    <city>
    <name>Abidjan</name>
    <state>Ivory Coast</state>
    <latitude>
    <deg>5</deg>
    <min>19</min>
    <sec>0</sec>
    <hemisphere>N</hemisphere>
    </latitude>
    <longitude>
    <deg>4</deg>
    <min>2</min>
    <sec>0</sec>
    <hemisphere>W</hemisphere>
    </longitude>
    </city>
    .....
    </cities>


    ASP (VB)
    --------
    Public lstbxCities1 As ListBox
    Public lblMon As Label

    Public Sub Page_Load(Source As Object, E As EventArgs)
    Dim dataSet As DataSet = LoadCityData()

    If Not dataSet Is Nothing Then
    Dim zRow As DataRow

    For Each zRow In dataSet.Tables(0).Rows
    Dim lstitmListItem As New ListItem()
    lstitmListItem.text = zRow.Item("name") & ", " & zRow.Item("state")

    '*** Problem Occurs Here ***
    lstitmListItem.value = "latitude:" &
    ToDegreeString(zRow.Item("latitude")) & _
    "longitude:" & ToDegreeString(zRow.Item("longitude"))

    lstbxCities1.Items.Add(lstitmListItem)
    Next
    lstbxCities1.Height = New Unit(20.0, UnitType.EM)
    End If

    End Sub

    Function ToDegreeString(dtblCoords As DataTable) As String
    Dim zRow As DataRow = dtblCoords.Rows(0)
    Dim dTotDegrees As Double

    Dim dDeg As Double = XmlConvert.ToDouble(zRow.Item("deg"))
    Dim dMin As Double = XmlConvert.ToDouble(zRow.Item("min"))
    Dim dSec As Double = XmlConvert.ToDouble(zRow.Item("sec"))

    dTotDegrees = DMSToDegrees(dDeg, dMin, dSec)

    Dim strOutput As String = XmlConvert.ToString(dTotDegrees) & "," &
    zRow.Item("hemisphere") & ";"

    Return strOutput
    End Function


    --
    Change "seven" to a digit to email me.
     
    N. Demos, Jun 9, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,617
  2. Bryan Ax
    Replies:
    6
    Views:
    559
    Peter Flynn
    May 17, 2006
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,477
    Dimitre Novatchev
    Aug 24, 2006
  4. Replies:
    1
    Views:
    1,222
    Joe Kesselman
    Nov 1, 2006
  5. Replies:
    1
    Views:
    582
    Martin Honnen
    May 8, 2007
Loading...

Share This Page