Pessoal estou tentando ler um XML com JDOM, estou utilizando o XPATH, poré esta gerando um erro como descrito abaixo…
O estranho tbm é que esse erro não cai no CATCH só consigo identifica-lo quando seleciono a linha de erro, já tentei várias Exceptions, até mesmo a da descrição do erro, mas mesmo assim o CATCH é ignorado…
[code]
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());
…
}[/code]
O erro é gerado nessa linha…
[color=red]XPath.newInstance("//Kml/Document/Placemark/LookAt");[/color]
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<
Alguem tem ideia do que esta acontecendo ?
abcs
será q pode ter alguma coisa haver com namespaces ?
o root node tem alguns:
<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">
mas nas TAGs do XML não tem nenhum prefixo de namespace olhem como esta:
<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>
Experimentei tirar os namespaces do KML e agora gera o seguinte erro quando tento ler o xml abaixo…
[color=red]The prefix “gx” for element “gx:altitudeMode” is not bound.[/color]
os dados q preciso pegar nao utilizam esse namespace gx…
tem mais algum arquivo q devo instalar além do JDOM.JAR ?
<?xml version="1.0" encoding="UTF-8"?>
<kml>
<Document>
<name>visao_inicial.kml</name>
<Style id="sn_noicon">
<IconStyle>
<Icon>
</Icon>
</IconStyle>
<ListStyle>
</ListStyle>
</Style>
<Placemark>
<LookAt>
<longitude>-47.82352833270107</longitude>
<latitude>-15.79446673639435</latitude>
<altitude>0</altitude>
<heading>6.522027165209955</heading>
<tilt>71.14594113424032</tilt>
<range>548.0846356994396</range>
<altitudeMode>relativeToGround</altitudeMode>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#sn_noicon</styleUrl>
<Point>
<altitudeMode>clampToGround</altitudeMode>
<gx:altitudeMode>clampToSeaFloor</gx:altitudeMode>
<coordinates>-47.82352833270107,-15.79446673639435,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Consegui resolver pelo StackOverFlow
java, xpath, kml, jdom