2011-03-04 114 views
2

我德尔福新手试图建立这样一个GPX文件,帮助创建GPX文件用Delphi 7

<?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> 

在此先感谢您的帮助

+0

您的第一个文件不是GPX文件。它甚至不是XML。请不要使用Internet Explorer打印它,而是使用普通的XML编辑器(有很多可以使用的)。 – 2011-03-04 22:07:09

回答

1

据我可以从例如来源,XML命名空间属性

告诉

的xmlns = “”

不应该存在。

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

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

不要(永远)使用

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

而是为文档分配一个名称空间,并添加具有特殊DOM方法的元素,这些元素具有额外的名称空间参数。

2

你可以看看GPX Editor是怎么做的。它是开放源码和德尔福应用程序..

在lib \文件夹中,您会发现可能对您感兴趣的文件。

+0

[Gpx编辑器](http://sourceforge.net/projects/gpxeditor/)使用[TurboPower XML合作伙伴](http://sourceforge.net/projects/tpxmlpartner/)。它被称为强大且有据可查的文件。 – menjaraz 2011-12-04 15:36:32

0

尝试使用Delphi XML数据绑定向导作为this answer suggests在Delphi中导入GPX XSD

它生成一个包含GPX结构的接口和类的单元。

然后从那里开始。