simplekml包给出了这个介绍示例:
import simplekml
kml = simplekml.Kml()
kml.newpoint(name="Kirstenbosch", coords=[(18.432314,-33.988862)]) # lon, lat, optional height
kml.save("botanicalgarden.kml")
我想将其扩展如下,以便在描述中添加一个超链接:
^{pr2}$但是,当我查看生成的KML文件时,超链接已转换为文本:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document id="feat_7">
<Placemark id="feat_8">
<name>Kirstenbosch</name>
<description><a href="https://en.wikipedia.org/wiki/Kirstenbosch_National_Botanical_Garden">Please go here</a></description>
<Point id="geom_3">
<coordinates>18.432314,-33.988862,0.0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
根据this page,我应该更像这样(超链接包装在CDATA中):
<description><![CDATA[
<A href="http://stlab.adobe.com/wiki/images/d/d3/Test.pdf">test link</A>]]></description>
我需要在SimpleXML中做些什么才能正确地获取.KML文件中的超链接?在
我找到了这个Google Earth KML教程https://developers.google.com/kml/documentation/kml_tut:
因此,您应该能够通过传递不带
<a>
标记的超链接来获得所需的行为,如下所示:simplekml还有一个parsetext()函数,它允许您关闭转义html字符的行为。所以你可以像这样使用你的原始代码:
^{pr2}$CDATA
标记还有一个特殊行为,它告诉GE不要转义HTML字符。你可以在这里阅读更多信息:https://developers.google.com/kml/documentation/kml_tutsimplekmlClaims to always parse the CDATA tag correctly,因此这可能是更高级链接的一个选项。在
相关问题 更多 >
编程相关推荐