GeoGet

Complete geocaching solutions

User Tools

Site Tools


user:navody:xml_parser

This is an old revision of the document!


XML parser

GeoGet obsahuje XML parser již dlouho, ale od verze 2.6 je tento parser dostupný i všem skriptům. Jako parser je použita volně dostupná knihovna. V uvedeném odkazu je k dispozici celý projekt, ale dokumentace je velmi strohá, a to je hodně nadnesené tvrzení.

Použití ve skriptu můžeme demonstrovat na jednoduchém příkladu:

uses simplexml;
...
procedure PluginStop;
var
  Xml: TJclSimpleXML;
  n: integer;
  s: string;
  ele: TJclSimpleXMLElem;
begin
  Xml := TJclSimpleXML.Create;
  try
    xml.loadfromfile('test.gpx', seAuto, 0);
    showmessage(XML.Root.Name);
    for n := 0 to XML.Root.Items.count - 1 do
    begin
      ele := XML.Root.Items[n]; 
      if ele.name = 'wpt' then
      begin
        s := 'X:' + ele.properties.ItemNamed['lat'].Value;
        s := s + ' Y:' + ele.properties.ItemNamed['lon'].Value;
        showmessage(s);
        ele := ele.items.Itemnamed['cache'];
        if assigned(ele) then
        begin
          ele := ele.items.Itemnamed['long_description'];
          if assigned(ele) then
            begin
              s := ele.value;
              Stringtofile(s, 'test.txt');
            end;
          end;
      end;
    end;
  finally
    xml.free;
  end;
end;
user/navody/xml_parser.1324412784.txt.gz · Last modified: 2011/12/20 00:00 (external edit)