我正在嘗試使用JDOM(XPATH)讀取KML。錯誤不會被Exceptions捕獲,只能通過鼠標懸停在代碼行XPath.newInstance(「// Kml/Document/Placemark/LookAt」);我看到的錯誤是:錯誤XPATH KML JDOM
XPath.newInstance("//Kml/Document/Placemark/LookAt"); = >Exception occurred in target VM: WEB9031: WebappClassLoader unable to load resource [java.lang.ExceptionInInitializerError], because it has not yet been started, or was already stopped<
我的代碼:
public void lerKML() throws Exception {
String path = req.getRealPath("/Usuarios/" + pe.getEmail() + "/"+ pe.getTitulo() + "/" + pe.getNomeArquivoKMLZ());
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new File(path));
XPath xPath = XPath.newInstance("//Kml/Document/Placemark/LookAt");
Element node = (Element) xPath.selectSingleNode(document.getRootElement());
...
}
示例KML文件:
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<Placemark>
<name>teste</name>
<LookAt>
<longitude>-47.82056628282606</longitude>
<latitude>-15.78921645504241</latitude>
<altitude>0</altitude>
<heading>0</heading>
<tilt>0</tilt>
<range>668.1932383230591</range>
</LookAt>
</Placemark>
</Document>
</Kml>
安迪,我想感謝的幫助。 現在起作用。 錯誤是命名空間和JAR jaxen 謝謝 – Ventura 2011-06-06 00:27:31