帮助用Delphi 7创建gpx文件

发布于 2024-10-20 12:14:10 字数 9668 浏览 3 评论 0原文

我是 Delphi 新手,试图创建这样的 GPX 文件,

 <?xml version="1.0" encoding="UTF-8" ?> 
- <gpx xmlns="http://www..." version="1.1" creator="EasyGPS 4.18" xmlns:xsi="http://www..." " xsi:schemaLocation="http://www..." >
- <metadata>
  <bounds minlat="19.38975200" minlon="-99.17971000" maxlat="19.39671900" maxlon="-99.17543500" /> 
- <extensions>
  <time xmlns="http://www...">2011-02-20T01:51:38.662Z</time> 
  </extensions>
  </metadata>
- <wpt lat="19.39671900" lon="-99.17820800">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>INDIANAPOLIS</name> 
  <sym>Residence</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>INDIANAPOLIS</label_text> 
  </label>
  </extensions>
  </wpt>
- <wpt lat="19.38975200" lon="-99.17543500">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>SUPERAMA</name> 
  <sym>Department Store</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." ">
  <label_text>SUPERAMA</label_text> 
  </label>
  </extensions>
  </wpt>
- <wpt lat="19.39119400" lon="-99.17971000">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>CUMULUS1</name> 
  <sym>Waypoint</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." ">
  <label_text>CUMULUS1</label_text> 
  </label>
  </extensions>
  </wpt>
- <rte>
- <extensions>
  <label xmlns="http://www..." /> 
  </extensions>
- <rtept lat="19.39671900" lon="-99.17820800">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>INDIANAPOLIS</name> 
  <sym>Residence</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>INDIANAPOLIS</label_text> 
  </label>
  </extensions>
  </rtept>
- <rtept lat="19.38975200" lon="-99.17543500">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>SUPERAMA</name> 
  <sym>Department Store</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www.topografix.com/GPX/gpx_overlay/0/3">
  <label_text>SUPERAMA</label_text> 
  </label>
  </extensions>
  </rtept>
- <rtept lat="19.39119400" lon="-99.17971000">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>CUMULUS1</name> 
  <sym>Waypoint</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>CUMULUS1</label_text> 
  </label>
  </extensions>
  </rtept>
- <rtept lat="19.39671900" lon="-99.17820800">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>INDIANAPOLIS</name> 
  <sym>Residence</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>INDIANAPOLIS</label_text> 
  </label>
  </extensions>
  </rtept>
  </rte>
  <extensions /> 
  </gpx>

我有以下代码

// root
iXml := XmlDoc.DOMDocument;
xmlNode := iXml.appendChild (iXml.createElement ('xml'));

iAttribute := iXml.createAttribute ('version');
iAttribute.nodeValue := '1.0';
xmlNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('encoding');
iAttribute.nodeValue := 'UTF-8';
xmlNode.attributes.setNamedItem (iAttribute);

//GPX
gpxNode := xmlNode.appendChild(iXml.createElement ('gpx'));

iAttribute := iXml.createAttribute ('xmlns');
iAttribute.nodeValue := http://www... ;
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('version');
iAttribute.nodeValue := '1.1';
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('creator');
iAttribute.nodeValue := http://www..." ;
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('xmlns:xsi');
iAttribute.nodeValue := 'http://www.w3.org/2001/XMLSchema-instance';
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('xsi:schemaLocation');
iAttribute.nodeValue := http://www..." ';
gpxNode.attributes.setNamedItem (iAttribute);

mNode := gpxNode.appendChild(iXml.createElement ('metadata'));

bNode := mNode.appendChild(iXml.createElement ('bounds'));

iAttribute := iXml.createAttribute ('minlat');
iAttribute.nodeValue := '19.38975200';
bNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('minlon');
iAttribute.nodeValue := '-99.17971000';
bNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('maxlat');
iAttribute.nodeValue := '19.39671900';
bNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('maxlon');
iAttribute.nodeValue := '-99.17543500';
bNode.attributes.setNamedItem (iAttribute);



trksegNode := gpxNode.appendChild(iXml.createElement ('wpt'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trksegNode.attributes.setNamedItem (iAttribute);

trksegNode := gpxNode.appendChild(iXml.createElement ('wpt'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.38975200';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17543500';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'SUPERAMA';
trksegNode.attributes.setNamedItem (iAttribute);

trksegNode := gpxNode.appendChild(iXml.createElement ('wpt'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39119400';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17971000';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'CUMULUS1';
trksegNode.attributes.setNamedItem (iAttribute);



trkptNode := gpxNode.appendChild (iXml.createElement ('rte'));

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trkNode.attributes.setNamedItem (iAttribute);

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.38975200';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17543500';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'SUPERAMA';
trkNode.attributes.setNamedItem (iAttribute);

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39119400';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17971000';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'CUMULUS1';
trkNode.attributes.setNamedItem (iAttribute);

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trkNode.attributes.setNamedItem (iAttribute);

但是当我尝试验证我的 GPX 文件时,它没有验证,“它不是 GPX 文件”

我认为我的主要问题在于我声明 GPX 节点的第一行,我几乎绝望了,任何帮助将非常感激

这是我通过代码获得的文件:

<xml version="1.0">
  <gpx xmlns="http://www.." version="1.1" creator="http://www..."  xmlns:xsi="http://www..." " xsi:schemaLocation="htthttp://www..." >
    <metadata xmlns="">
      <bounds minlat="19.38975200" minlon="-99.17971000" maxlat="19.39671900" maxlon="-99.17543500"/>
    </metadata>
    <wpt xmlns="" lat="19.39671900" lon="-99.17820800" name="INDIANAPOLIS"/>
    <wpt xmlns="" lat="19.38975200" lon="-99.17543500" name="SUPERAMA"/>
    <wpt xmlns="" lat="19.39119400" lon="-99.17971000" name="CUMULUS1"/>
    <rte xmlns="">
      <rtept lat="19.39671900" lon="-99.17820800" name="INDIANAPOLIS"/>
      <rtept lat="19.38975200" lon="-99.17543500" name="SUPERAMA"/>
      <rtept lat="19.39119400" lon="-99.17971000" name="CUMULUS1"/>
      <rtept lat="19.39671900" lon="-99.17820800" name="INDIANAPOLIS"/>
    </rte>
  </gpx>
</xml>

提前感谢您的帮助

I'm Delphi newbie trying to create a GPX file like this,

 <?xml version="1.0" encoding="UTF-8" ?> 
- <gpx xmlns="http://www..." version="1.1" creator="EasyGPS 4.18" xmlns:xsi="http://www..." " xsi:schemaLocation="http://www..." >
- <metadata>
  <bounds minlat="19.38975200" minlon="-99.17971000" maxlat="19.39671900" maxlon="-99.17543500" /> 
- <extensions>
  <time xmlns="http://www...">2011-02-20T01:51:38.662Z</time> 
  </extensions>
  </metadata>
- <wpt lat="19.39671900" lon="-99.17820800">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>INDIANAPOLIS</name> 
  <sym>Residence</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>INDIANAPOLIS</label_text> 
  </label>
  </extensions>
  </wpt>
- <wpt lat="19.38975200" lon="-99.17543500">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>SUPERAMA</name> 
  <sym>Department Store</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." ">
  <label_text>SUPERAMA</label_text> 
  </label>
  </extensions>
  </wpt>
- <wpt lat="19.39119400" lon="-99.17971000">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>CUMULUS1</name> 
  <sym>Waypoint</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." ">
  <label_text>CUMULUS1</label_text> 
  </label>
  </extensions>
  </wpt>
- <rte>
- <extensions>
  <label xmlns="http://www..." /> 
  </extensions>
- <rtept lat="19.39671900" lon="-99.17820800">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>INDIANAPOLIS</name> 
  <sym>Residence</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>INDIANAPOLIS</label_text> 
  </label>
  </extensions>
  </rtept>
- <rtept lat="19.38975200" lon="-99.17543500">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>SUPERAMA</name> 
  <sym>Department Store</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www.topografix.com/GPX/gpx_overlay/0/3">
  <label_text>SUPERAMA</label_text> 
  </label>
  </extensions>
  </rtept>
- <rtept lat="19.39119400" lon="-99.17971000">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>CUMULUS1</name> 
  <sym>Waypoint</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>CUMULUS1</label_text> 
  </label>
  </extensions>
  </rtept>
- <rtept lat="19.39671900" lon="-99.17820800">
  <time>2011-02-20T01:44:26.284Z</time> 
  <name>INDIANAPOLIS</name> 
  <sym>Residence</sym> 
- <extensions>
  <time xmlns="http://www..." </time> 
- <label xmlns="http://www..." >
  <label_text>INDIANAPOLIS</label_text> 
  </label>
  </extensions>
  </rtept>
  </rte>
  <extensions /> 
  </gpx>

I have the following code

// root
iXml := XmlDoc.DOMDocument;
xmlNode := iXml.appendChild (iXml.createElement ('xml'));

iAttribute := iXml.createAttribute ('version');
iAttribute.nodeValue := '1.0';
xmlNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('encoding');
iAttribute.nodeValue := 'UTF-8';
xmlNode.attributes.setNamedItem (iAttribute);

//GPX
gpxNode := xmlNode.appendChild(iXml.createElement ('gpx'));

iAttribute := iXml.createAttribute ('xmlns');
iAttribute.nodeValue := http://www... ;
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('version');
iAttribute.nodeValue := '1.1';
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('creator');
iAttribute.nodeValue := http://www..." ;
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('xmlns:xsi');
iAttribute.nodeValue := 'http://www.w3.org/2001/XMLSchema-instance';
gpxNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('xsi:schemaLocation');
iAttribute.nodeValue := http://www..." ';
gpxNode.attributes.setNamedItem (iAttribute);

mNode := gpxNode.appendChild(iXml.createElement ('metadata'));

bNode := mNode.appendChild(iXml.createElement ('bounds'));

iAttribute := iXml.createAttribute ('minlat');
iAttribute.nodeValue := '19.38975200';
bNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('minlon');
iAttribute.nodeValue := '-99.17971000';
bNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('maxlat');
iAttribute.nodeValue := '19.39671900';
bNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('maxlon');
iAttribute.nodeValue := '-99.17543500';
bNode.attributes.setNamedItem (iAttribute);



trksegNode := gpxNode.appendChild(iXml.createElement ('wpt'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trksegNode.attributes.setNamedItem (iAttribute);

trksegNode := gpxNode.appendChild(iXml.createElement ('wpt'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.38975200';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17543500';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'SUPERAMA';
trksegNode.attributes.setNamedItem (iAttribute);

trksegNode := gpxNode.appendChild(iXml.createElement ('wpt'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39119400';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17971000';
trksegNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'CUMULUS1';
trksegNode.attributes.setNamedItem (iAttribute);



trkptNode := gpxNode.appendChild (iXml.createElement ('rte'));

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trkNode.attributes.setNamedItem (iAttribute);

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.38975200';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17543500';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'SUPERAMA';
trkNode.attributes.setNamedItem (iAttribute);

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39119400';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17971000';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'CUMULUS1';
trkNode.attributes.setNamedItem (iAttribute);

trkNode := trkptNode.appendChild (iXml.createElement ('rtept'));

iAttribute := iXml.createAttribute ('lat');
iAttribute.nodeValue := '19.39671900';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('lon');
iAttribute.nodeValue := '-99.17820800';
trkNode.attributes.setNamedItem (iAttribute);

iAttribute := iXml.createAttribute ('name');
iAttribute.nodeValue := 'INDIANAPOLIS';
trkNode.attributes.setNamedItem (iAttribute);

But when I try to validate my GPX file it doesn't validates, "it is not a GPX file"

I think my main problem is on the first rows where I declare the GPX node, I am almost desperate, any help will be really appreciated

Here is the file that I get with the code:

<xml version="1.0">
  <gpx xmlns="http://www.." version="1.1" creator="http://www..."  xmlns:xsi="http://www..." " xsi:schemaLocation="htthttp://www..." >
    <metadata xmlns="">
      <bounds minlat="19.38975200" minlon="-99.17971000" maxlat="19.39671900" maxlon="-99.17543500"/>
    </metadata>
    <wpt xmlns="" lat="19.39671900" lon="-99.17820800" name="INDIANAPOLIS"/>
    <wpt xmlns="" lat="19.38975200" lon="-99.17543500" name="SUPERAMA"/>
    <wpt xmlns="" lat="19.39119400" lon="-99.17971000" name="CUMULUS1"/>
    <rte xmlns="">
      <rtept lat="19.39671900" lon="-99.17820800" name="INDIANAPOLIS"/>
      <rtept lat="19.38975200" lon="-99.17543500" name="SUPERAMA"/>
      <rtept lat="19.39119400" lon="-99.17971000" name="CUMULUS1"/>
      <rtept lat="19.39671900" lon="-99.17820800" name="INDIANAPOLIS"/>
    </rte>
  </gpx>
</xml>

Thanks in advance for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往昔成烟 2024-10-27 12:14:11

据我从示例源中可以看出,XML 命名空间属性

xmlns=""

不应该在那里。

原始文件中的文档元素使用 xmlns="http://www..." 命名空间。它的子元素继承这个命名空间。但是通过在 Delphi 中添加 xmlns="",子元素将具有不同的(“默认”)命名空间。这将导致 XML 无效(您可以尝试使用 XML 验证器)。

您需要告诉 Delphi DOM 根元素具有给定的命名空间。

不要(永远不要)使用

iAttribute := iXml.createAttribute
('xmlns');

相反,为文档分配一个命名空间,并使用具有附加命名空间参数的特殊 DOM 方法添加元素。

As far as I can tell from the example source, the XML namespace attribute

xmlns=""

should not be there.

The document element in the original file uses the xmlns="http://www..." namespace. Its child elements inherit this namespace. But by adding the xmlns="" in Delphi, the child elements have a different ('default') namespaces. which will cause the XML to be invalid (you can try with a XML validator).

You need to tell the Delphi DOM that the root element has the given namespace.

Do not (never ever) use

iAttribute := iXml.createAttribute
('xmlns');

Instead, assign a namespace to the document and add elements with the special DOM methods which have an additional namespace parameter.

你的背包 2024-10-27 12:14:11

尝试使用 Delphi XML 数据在 Delphi 中导入 GPX XSD绑定向导为这个答案建议

它生成一个带有围绕 GPX 结构的接口和类的单元。

然后从那里出发。

Try to import the GPX XSD in your Delphi using the Delphi XML Data Binding Wizard as this answer suggests.

It generates a unit with interfaces and classes wrapping around the GPX structure.

Then go from there.

小帐篷 2024-10-27 12:14:10

您可以看看 GPX Editor 是如何做到这一点的。它是开源的 Delphi 应用程序。

在 lib\ 文件夹中,您将找到您可能感兴趣的文件。

You could take a look at how GPX Editor does the trick. It's open source and a Delphi application..

In the lib\ folder you'll find files that might be of interest for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文