vylan / javaapiforkml

Automatically exported from code.google.com/p/javaapiforkml
0 stars 0 forks source link

Can't read kml #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I jsut downloaded the  jak from "http://labs.micromata.de/display/jak/Download";
But i found, i can't read kml, even created by jak.
Here is my piece of code.
public static void main(String[] args) {
        Kml kml = Kml.unmarshal("D:/doc/admod/kml/test.kml");
        Document document = (Document) kml.getFeature();
        JAXBContext j;
        kml.marshal();
    }
And the kml file just created by jak
<?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:atom="http://www.w3.org/2005/Atom" 
xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
    <Document>
        <name>JAK Example1</name>
        <open>1</open>
        <Folder>
            <name>Continents with Earth's surface</name>
            <open>1</open>
        </Folder>
    </Document>
</kml>
When i try to read the file. I got these exceptions.
javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: Content is not allowed in prolog.]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(Unknown Source)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:523)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:220)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:189)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown Source)
    at de.micromata.opengis.kml.v_2_2_0.Kml.unmarshal(Kml.java:846)
    at tuangoking.com.KmlTest.main(KmlTest.java:11)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at de.micromata.opengis.kml.v_2_2_0.NamespaceFilterXMLReader.parse(NamespaceFilterXMLReader.java:63)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:216)
    ... 5 more
Exception in thread "main" java.lang.NullPointerException
    at tuangoking.com.KmlTest.main(KmlTest.java:12)

Original issue reported on code.google.com by kli...@gmail.com on 26 Nov 2010 at 9:48

GoogleCodeExporter commented 9 years ago
It's all my fault.
The correct code should be this:
Kml kml = Kml.unmarshal(new 
FileInputStream("E:/software/开发相关/java/javaApiForKml/exampledata/worldBo
rders.kml"));
        Document document = (Document) kml.getFeature();

Original comment by kli...@gmail.com on 30 Nov 2010 at 2:37