Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6003523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:08:00+00:00 2026-05-23T01:08:00+00:00

I am trying to read a KML with JDOM(XPATH). The error is not caught

  • 0

I am trying to read a KML with JDOM(XPATH). The error is not caught by Exceptions, only with mouse over code at line XPath.newInstance(“//Kml/Document/Placemark/LookAt”); The error I am seeing is:

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<

My 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());
    ...
}

Example KML file:

<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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:08:01+00:00Added an answer on May 23, 2026 at 1:08 am

    The error you are seeing, it looks like a webapp deployment issue. If you post the full stack trace with the Cause I may be able to help further. Have you included all the required jars to the project?

    However, there are a couple of other problems that to be fixed otherwise the code will not work as expected.

    Firstly, the KML file is not valid. The closing tag </Kml> does not match the opening tag <kml>. XML is case-sensitive.

    Secondly, the XPath you are using is not namespace aware. A tag without a prefix is assumed to be in the default namespace. You need to add this default namespace.

    I have made a small demo that loads and parses the following KML (corrected) file (save as test.kml)

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <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>
    

    The demo class (save as a file called ReadKml.java and put in the same directory as test.kml)

    import java.io.*;
    import org.jdom.input.SAXBuilder;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.xpath.XPath;
    
    public class ReadKml {
        public static void main(String args[]) throws Exception {
            File kmlFile = new File("test.kml");
            SAXBuilder builder = new SAXBuilder();
            Document document = builder.build(kmlFile);
    
            XPath xPath = XPath.newInstance("//k:kml/k:Document/k:Placemark/k:LookAt");
            xPath.addNamespace("k", document.getRootElement().getNamespaceURI());
    
            Element node = (Element) xPath.selectSingleNode(document.getRootElement());
            System.out.println(node.getName());
        }
    }
    

    The demo requires JDOM to be on the classpath for compilation, for example on Windows to compile the demo type javac -cp jars\jdom.jar ReadKml.java. Running the demo requires Jaxen as well, so add that to the classpath, for example java -cp .;jars\jdom.jar;jars\jaxen.jar ReadKml

    This results in the System.output of LookAt, which is simply the Element.name().

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am trying to read web page from java code and its fine for general
I am trying to read a binary file (only 32 bits long) into a
I'm trying to read a KML file in a C #. I need to
Im trying to read in image file from a server , with the code
I'm trying to read weather information from the Google Weather API. My Code looks
I am trying to read xml string from DB. However my code is erroring?
Im trying to read xml into SQL and get an error at the ds.ReadXml(C:\test.xml);
Trying to read an RSS and select information using Linq but can't seem to
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
I'm currently trying to read in an XML file, make some minor changes (alter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.