views:

156

answers:

1

I am a little new to this, but I need to convert the below XML to KML format so I can feed it into Google maps. Can anyone help with this?

<messageList>
<totalCount>1</totalCount>
−
<message>
<esn>0-7396996</esn>
<esnName>JOHN</esnName>
<messageType>TEST</messageType>
<messageDetail> ALL IS WELL AT CURRENT LOCATION.</messageDetail>
<timestamp>2010-05-24T00:39:12.000Z</timestamp>
<timeInGMTSecond>1274661552</timeInGMTSecond>
<latitude>25.19483</latitude>
<longitude>65.7162</longitude>
</message>
</messageList>
+5  A: 

You could apply an XSL template translator. Something along these lines:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

<xsl:template match="/">
    <kml xmlns="http://www.opengis.net/kml/2.2"&gt;
        <Document>
            <xsl:apply-templates select="messageList" />
        </Document>
    </kml>
</xsl:template>

<xsl:template match="messageList">
    <name>My Generated KML</name>
    <xsl:apply-templates select="message" />
</xsl:template>

<xsl:template match="message">
    <Placemark>
        <name><xsl:value-of select="esnName" /></name>
        <Point>
            <coordinates>
                <xsl:value-of select="latitude" />,<xsl:value-of select="longitude" />
            </coordinates>
        </Point>
    </Placemark>
</xsl:template>

</xsl:stylesheet>

(basic KML format from a documentation example)

KML is an extensive format, and you can add much more information than the couple of elements I have here.

amphetamachine