我在尝试解析KML文档时遇到此错误:
com.bmw.cockpitm.business.backend.spec.ImportException: Error parsing KML data
at com.bmw.cockpitm.data.importers.riskmanagement.SimpleKmlDataImporter.importData(SimpleKmlDataImporter.java:120)
at com.bmw.cockpitm.jobs.ImportRiskEventsJob.execute(ImportRiskEventsJob.java:105)
at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 50; White spaces are required between publicId and systemId.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at com.bmw.cockpitm.data.importers.riskmanagement.SimpleKmlDataImporter.loadEventsData(SimpleKmlDataImporter.java:261)
at com.bmw.cockpitm.data.importers.riskmanagement.SimpleKmlDataImporter.importData(SimpleKmlDataImporter.java:100)
... 3 more
可以找到KML文档here。
很可能在格式化kml文件时出现了一些错误,但我不知道它在哪里以及它是什么。欢迎任何帮助。
KML的一部分:
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<description>
The Global Disaster Alert and Coordination System provides near real-time alerts about natural disasters around the world and tools to facilitate response coordination, including news, maps and V. OSOCC. GDACS is a joint initiative of the European Commission and the United Nations.
</description>
<name>Global Disaster Alert and Coordination system</name>
<Folder>
<name><![CDATA[ Tropical Cyclone HOWARD-16]]></name>
<Placemark id='TC_1000281'>
<name>Green Alert for Tropical Cyclone HOWARD-16 </name>
<extendeddata>
<data name="eventtype">
<value>TC</value>
</data>
<data name = "eventid" >
<value>1000281</value>
</data >
<data name="episodeid">
<value>8</value>
</data>
</extendeddata>
<snippet></snippet>
答案 0 :(得分:1)
示例KML文档不是有效的KML文档。它有许多错误,可能导致各种解析错误。但是,它是一个格式良好的XML文档,其中起始和结束标记匹配,并引用属性。
以下描述了三种类型的错误:
第一种错误是使用错误的元素名称。 KML元素区分大小写。使用错误的元素通常会在Google地球中忽略这些元素。 XML解析器可能会也可能不会忽略这些错误。
package restaurantelospavorreales;
import java.util.LinkedList;
import java.sql.*;
import javax.swing.JOptionPane;
/**
* @author luisricardo
*/
public class BuscarProducto {
public LinkedList Producto(int Identificador, String Tipo, int Cantidad, int Mesa){
LinkedList Datos = new LinkedList();
Datos.add(Mesa);
String Query;
Query = "SELECT ID, Nombre, Precio FROM '" + Tipo + "' WHERE ID = " + Identificador ; //Se construye el Query
//Se realiza la conexion
try {
ResultSet Res = new DB_Conecttion().Conexion().createStatement().executeQuery(Query);
Datos.addLast(Res.getString(1));
Datos.addLast(Res.getString(2));
Datos.addLast(Res.getString(3));
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Error en la conexion a la DB :" + e);
}
return Datos;
}
}
下一类错误是由无序元素引起的。 KML 2.2具有严格的元素顺序,元素应以正确的顺序出现。这可能是KML文件中最常见的错误。
示例:
Example: `<extendeddata>` element must be renamed with `<ExtendedData>`.
<Document>
<description>The Global Disaster Alert...</description>
<name>Global Disaster Alert and Coordination system</name>
字段必须后跟<name>
元素。
<description>
必须首先使用KML Validator或Feed Validator等验证程序验证KML文档。还有一个命令行XML Validator工具,可以验证任何大小的KML或KMZ文件。然后修复验证错误。
或者,您可能希望在SAX解析器中禁用模式和/或验证检查。