How to read GPS XML file on Map Basic?

520 Views Asked by At

I want to write a program which reads XML file on below.

<?xml version="1.0" encoding="UTF-8"?>
-<GPSLog cultureInfo="tr-TR" name="GPS 1_Log" version="4.0.3860">
-<PVTInfo Mode="GPSModeType3D" Status="GPSStatusTypeDOINGFIXES" TDOP="0"                                                       
VDOP="0,7" HDOP="0,7" PDOP="1,476482" Depth="0"                            
MagneticVariation="-5,19999999999999" Heading="338,9" Speed="0,05"                       
GeoidHeight="1089,9" EllipsoidHeight="1120" Longitude="35,5297421666667"
Latitude="38,7525401666667" LastTime="51969,2" Time="51969,3"                               
ValidFlags="14327" >
-<Satellites>
<SatInfo Used="True" SNR="42" Azimuth="242" Elevation="70" PRN="69"/>
<SatInfo Used="True" SNR="43" Azimuth="188" Elevation="61" PRN="28"/>
<SatInfo Used="True" SNR="47" Azimuth="282" Elevation="41" PRN="5"/>
<SatInfo Used="True" SNR="47" Azimuth="202" Elevation="35" PRN="10"/>
<SatInfo Used="True" SNR="45" Azimuth="53" Elevation="45" PRN="7"/>
<SatInfo Used="True" SNR="38" Azimuth="123" Elevation="31" PRN="9"/>
<SatInfo Used="True" SNR="35" Azimuth="172" Elevation="28" PRN="74"/>
<SatInfo Used="True" SNR="32" Azimuth="62" Elevation="13" PRN="91"/>
<SatInfo Used="True" SNR="47" Azimuth="10" Elevation="69" PRN="30"/>
<SatInfo Used="True" SNR="40" Azimuth="324" Elevation="33" PRN="78"/>  
<SatInfo Used="True" SNR="40" Azimuth="347" Elevation="63" PRN="72"/>
<SatInfo Used="True" SNR="38" Azimuth="310" Elevation="25" PRN="13"/>
<SatInfo Used="False" SNR="37" Azimuth="139" Elevation="36" PRN="39"/>
<SatInfo Used="False" SNR="38" Azimuth="264" Elevation="34" PRN="85"/>
<SatInfo Used="False" SNR="33" Azimuth="59" Elevation="15" PRN="19"/>
<SatInfo Used="False" SNR="38" Azimuth="181" Elevation="12" PRN="20"/>
<SatInfo Used="False" SNR="19" Azimuth="110" Elevation="7" PRN="84"/
</Satellites>
</PVTInfo>

I need Lat, Long and time values so I want to skip other thing while reading the file . I'll use these points for drawing line objects.

Thanks in advance

1

There are 1 best solutions below

0
On

MapBasic provides a lot of XML specific functions. Your code may look like this (not tested):

Dim xmlDoc as MIXmlDocument
Dim xmlNode As MIXmlNode
Dim res Integer
Dim pbParsingError As SmallInt
Dim lat as String

hxml = MIXmlDocumentCreate( )
res := MIXmlDocumentLoad(xmlDoc, "C:\Your_Path\Your_File.xml", pbParsingError, 0, 0)
xmlNode = MIXmlDocumentGetRootNode(xmlDoc)
xmlNode = MIXmlSelectSingleNode(xmlNode, "/GPSLog/PVTInfo")
res = MIXmlNodeGetAttributeValue(xmlNode, "Latitude", lat, 20)
Print "Latitude = " + lat

MIXmlDocumentDestroy(xmlDoc)