Search code examples
javamapinfomap-basic

How can I regulate data from a text file with java?


To be more specific ; I have a xml file which has a lots of letters and gps data like this one ;

</Satellites>
</PVTInfo>
<PVTInfo ValidFlags="14327" Time="51973,3" LastTime="51973,1"
 Latitude="38,7525418333333" Longitude="35,5297423333333" 
 EllipsoidHeight="1120"
 GeoidHeight="1089,9" Speed="0,0166666666666667" Heading="338,9" 
 MagneticVariation="-5,19999999999999" Depth="0" PDOP="1,476482" HDOP="0,7"
 VDOP="0,7" TDOP="0" Status="GPSStatusTypeDOINGFIXES" Mode="GPSModeType3D">
<Satellites>
  <SatInfo PRN="69" Elevation="70" Azimuth="240" SNR="43" Used="True" />
  <SatInfo PRN="28" Elevation="61" Azimuth="188" SNR="44" Used="True" />
  <SatInfo PRN="5" Elevation="41" Azimuth="282" SNR="47" Used="True" />
  <SatInfo PRN="10" Elevation="35" Azimuth="202" SNR="47" Used="True" />
  <SatInfo PRN="7" Elevation="45" Azimuth="53" SNR="45" Used="True" />
  <SatInfo PRN="9" Elevation="31" Azimuth="123" SNR="39" Used="True" />
  <SatInfo PRN="74" Elevation="28" Azimuth="172" SNR="35" Used="True" />
  <SatInfo PRN="91" Elevation="13" Azimuth="62" SNR="31" Used="True" />
  <SatInfo PRN="30" Elevation="69" Azimuth="10" SNR="47" Used="True" />
  <SatInfo PRN="78" Elevation="33" Azimuth="324" SNR="39" Used="True" />
  <SatInfo PRN="72" Elevation="63" Azimuth="347" SNR="39" Used="True" />
  <SatInfo PRN="13" Elevation="25" Azimuth="310" SNR="37" Used="True" />
  <SatInfo PRN="39" Elevation="36" Azimuth="139" SNR="37" Used="False" />
  <SatInfo PRN="85" Elevation="34" Azimuth="264" SNR="38" Used="False" />
  <SatInfo PRN="19" Elevation="15" Azimuth="59" SNR="33" Used="False" />
  <SatInfo PRN="20" Elevation="12" Azimuth="181" SNR="38" Used="False" />
</Satellites> 

The file is like 35 pages. So I have lots of lines to procces. All I need is point number, Latitude and Longitude. I'm using Map Info to procces this data so I need these information in this format ;

"Number [TAB] Latitude [TAB] Longitude"

Otherwise Map Info cant proccess this data.

Thanks in advance...


Solution

  • There are many ways to read and parse XML. Take a look at these Java XML tutorials. DOM parsing is simpler but you'll need enough memory to hold the entire document (XML file). If this is a recurring need then it's worth spending the time to learn JAXB, otherwise I'd just cobble together something by following an example.

    See also this SO question - there's sample code in one of the answers.