我正在尝试使用 pykml 解析包含多个地标的 kml 文件。我想编辑 kml 描述中的 HTML 代码,主要用于 Google 地球中地理数据的可视化目的。我研究了很多方法来做到这一点:
但是,我总是得到如下所示的 lxml 错误。:(
Traceback (most recent call last):
File "C:\Users\Arellano\Copy\BSGE\2015-2016 SUMMER\trial7.py", line 5, in <module>
root = parser.fromstring(open('trim_KML.kml', 'r').read())
File "C:\Program Files (x86)\Python2.7.10\lib\site-packages\pykml-0.1.0-py2.7.egg\pykml\parser.py", line 41, in fromstring
return objectify.fromstring(text)
File "src/lxml/lxml.objectify.pyx", line 1801, in lxml.objectify.fromstring (src\lxml\lxml.objectify.c:25171)
File "src/lxml/lxml.etree.pyx", line 3213, in lxml.etree.fromstring (src\lxml\lxml.etree.c:77697)
File "src/lxml/parser.pxi", line 1819, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:116494)
File "src/lxml/parser.pxi", line 1707, in lxml.etree._parseDoc (src\lxml\lxml.etree.c:115144)
File "src/lxml/parser.pxi", line 1079, in lxml.etree._BaseParser._parseDoc (src\lxml\lxml.etree.c:109543)
File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src\lxml\lxml.etree.c:103404)
File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src\lxml\lxml.etree.c:105058)
File "src/lxml/parser.pxi", line 613, in lxml.etree._raiseParseError (src\lxml\lxml.etree.c:103967)
XMLSyntaxError: Namespace prefix xsi for schemaLocation on Document is not defined, line 3, column 32
这是我的代码片段:(它应该基于我的一个来源工作)
from pykml import parser
root = parser.fromstring(open('trim_KML.kml', 'r').read())
print etree.tostring(root.Document.Placemark.LineString.Description)
我已经安装了 pykml 和 lxml 3.6.0,我目前正在使用我的 Python 2.7.10。kml 文件包含行。(kml 链接:https ://sites.google.com/site/kmlhostingmwss/trim.kml )我的 ArcGIS 10.2 也有 Python 2.7。
我是使用 kml 文件的新手。有人可以告诉我我做错了什么吗?或者有没有更简单的方法来编辑 kml 文件的描述?非常感谢你。:)))