如何在java上读取kml文件

时间:2016-01-28 16:23:33

标签: java xml kml

如果我将它切换到xml它可以正常工作,但没有任何东西。以为它基本上是一样的东西,可能会遗漏一些愚蠢的东西,或者完全搞砸了对不起,但是非常感谢帮助。基本上只是想在java上读取kml文件数据。

包mysqlcon;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;

public class ReadXMLFile {

  public static void main(String argv[]) {

    try {

    File fXmlFile = new File("C:/Users/D/Desktop/mysql/mappedv.kml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);


    doc.getDocumentElement().normalize();

    System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

    NodeList nList = doc.getElementsByTagName("mappedv");

    System.out.println("----------------------------");

    for (int temp = 0; temp < nList.getLength(); temp++) {

        Node nNode = nList.item(temp);

        System.out.println("\nCurrent Element :" + nNode.getNodeName());

        if (nNode.getNodeType() == Node.ELEMENT_NODE) {

            Element eElement = (Element) nNode;


            System.out.println("coordinates : " + eElement.getElementsByTagName("coordinates").item(0).getTextContent());

        }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
  }

}

0 个答案:

没有答案