467,161 Members | 848 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Problem accessing complex XML child node when using Dataset

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.
Nov 19 '05 #1
  • viewed: 1370
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tony Girgenti | last post: by
4 posts views Thread by SteveT | last post: by
2 posts views Thread by Richard Carpenter | last post: by
2 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.