Question

I plan to adopt once and for all handy a tool for handling the creation of gpx files.

I believe SimpleStorage which is a OmniXML based storage suited for easy XML data management, data storage and data interchange beetween systems fits it.

Here is an (incomplete) snippet to generate a bare bone gpx file that way :

function CreateGpx: ISimpleStorage;
const
  versionStr = '1.1';
  creatorStr = 'MyGpxCreatorSSway';

  xmlnsStr = 'http://www.topografix.com/GPX/1/1';
  xmlns_xsiStr = 'http://www.w3.org/2001/XMLSchema-instance';
  xsiStr: string =  xmlnsStr+' '+
                    xmlnsStr+'/gpx.xsd';

begin
  Result := CreateStorage('gpx');

  CreateBuilder(Result).Construct(
  [
    AddAttr('xmlns',xmlnsStr),
    AddAttr('version',versionStr),
    AddAttr('creator',creatorStr),
    AddAttr('xmlns:xsi',xmlns_xsiStr),
    AddAttr('xsi:schemaLocation',xsiStr),
    //
    AddElement('metadata',
    [
      AddElement('bounds',
      [
        AddAttr('minlat','90.00000000'),
        AddAttr('minlon','180.00000000'),
        AddAttr('maxlat','-90.00000000'),
        AddAttr('maxlon','-180.00000000')
      ]),
      AddElement('extensions',[])
    ]),
    AddElement('extensions',[])
  ]
  );
end;

Please help me !

Was it helpful?

Solution

I've spotted relevant post from Miha Remec on OmniXML site.

One possible answer to my question might be boiled down to as follows :

with OwnerDocument(Result.XMLNode) do
begin
  InsertBefore(CreateProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"'), DocumentElement)
end;

to append just after the instruction line :

  Result := CreateStorage('gpx'); 

OTHER TIPS

uses
  OmniXML,
  OmniXMLUtils;

function CreateGpx: ISimpleStorage;
{ ... }
var
  xmlDocument: IXMLDocument;
  xmlProcessingInstruction: IXMLProcessingInstruction;
  fisrtChild: IXMLNode;
begin
  { ... }
  xmlDocument := OmniXMLUtils.OwnerDocument(Result.Node.ParentNode);
  if OmniXMLUtils.FindProcessingInstruction(xmlDocument) = nil then
  begin
    xmlProcessingInstruction := xmlDocument.CreateProcessingInstruction('xml', 'version="1.0" encoding="utf-8"');

    fisrtChild := xmlDocument.FirstChild;
    if fisrtChild = nil then
    begin
      xmlDocument.AppendChild(xmlProcessingInstruction);
    end
    else
    begin
      xmlDocument.InsertBefore(xmlProcessingInstruction, fisrtChild);
    end;
  end;
  { ... }
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top