EDN Admin
Well-known member
Ok, so ive been reading some data from KML / XML files no problem, items of interest are latitude and longitude and various other bits of info, ive been using the following code:
<pre class="prettyprint lang-vb Dim XmlReader As XmlTextReader
Try
XmlReader = New XmlTextReader(String.Concat(FileDir, Filename))
Dim intID As Integer
Dim strCoord As String
Dim strHeading As String
While XmlReader.Read()
extract the "coordinates" value when the reader reach the "Point" element.
If XmlReader.Name.ToString() = "Point" Then
If XmlReader.HasAttributes Then
While XmlReader.MoveToNextAttribute()
If XmlReader.Name = "coordinates" Then
intID = CInt(XmlReader.Value)
End If
End While
End If
End If
If XmlReader.Name.ToString() = "coordinates" Then strCoord = Trim(XmlReader.ReadString())
If XmlReader.Name.ToString() = "Point" And XmlReader.NodeType.ToString() = "EndElement" Then
Dim varLat, varLon As Decimal
varLat = Split(strCoord, ",")(1)
varLon = Split(strCoord, ",")(0)
Me.Lat1_Textbox.Text = varLat
Me.Lon1_Textbox.Text = varLon
End If
End While
Finally
If Not XmlReader Is Nothing Then XmlReader.Close()
End Try
[/code]
So, the above is reading from the <point> </point> and extracting the lat and lon. Happy days.
Now in another KML file there is the following:
<pre class="prettyprint <MultiGeometry>
<Point><coordinates>
0.00000,0.00000
</coordinates></Point>
<!--087°-->
<LineString><coordinates>
0.00000,0.00000
0.09986,0.00523
</coordinates></LineString>
</MultiGeometry>[/code]
Now, Im interesting in extracting the 087 (this is a bearing). How do I get the xmlreader to get to the <!-- line?
Thanks in advance.
View the full article
<pre class="prettyprint lang-vb Dim XmlReader As XmlTextReader
Try
XmlReader = New XmlTextReader(String.Concat(FileDir, Filename))
Dim intID As Integer
Dim strCoord As String
Dim strHeading As String
While XmlReader.Read()
extract the "coordinates" value when the reader reach the "Point" element.
If XmlReader.Name.ToString() = "Point" Then
If XmlReader.HasAttributes Then
While XmlReader.MoveToNextAttribute()
If XmlReader.Name = "coordinates" Then
intID = CInt(XmlReader.Value)
End If
End While
End If
End If
If XmlReader.Name.ToString() = "coordinates" Then strCoord = Trim(XmlReader.ReadString())
If XmlReader.Name.ToString() = "Point" And XmlReader.NodeType.ToString() = "EndElement" Then
Dim varLat, varLon As Decimal
varLat = Split(strCoord, ",")(1)
varLon = Split(strCoord, ",")(0)
Me.Lat1_Textbox.Text = varLat
Me.Lon1_Textbox.Text = varLon
End If
End While
Finally
If Not XmlReader Is Nothing Then XmlReader.Close()
End Try
[/code]
So, the above is reading from the <point> </point> and extracting the lat and lon. Happy days.
Now in another KML file there is the following:
<pre class="prettyprint <MultiGeometry>
<Point><coordinates>
0.00000,0.00000
</coordinates></Point>
<!--087°-->
<LineString><coordinates>
0.00000,0.00000
0.09986,0.00523
</coordinates></LineString>
</MultiGeometry>[/code]
Now, Im interesting in extracting the 087 (this is a bearing). How do I get the xmlreader to get to the <!-- line?
Thanks in advance.
View the full article