Are you sure the file you are trying to parse is available? As this program
is written it assumes the file is in the same directory from which you are
running the java process from? Is that true? And you are sure the contents
of the file are valid?

On Thu, Sep 16, 2010 at 11:07 PM, eros <[email protected]> wrote:

>
> I am trying to parse a gml 3.2.1 but getting the following error:
>
> [Fatal Error] :1:1: Premature end of file.
> org.xml.sax.SAXParseException: Premature end of file.
>        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
>        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
>        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
>        at demo.gml.geotools.GmlToShape.testWithSchema(GmlToShape.java:55)
>        at demo.gml.geotools.GmlToShape.main(GmlToShape.java:44)
>
>
>
> here's my java code
>
> package demo.gml.geotools;
>
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileNotFoundException;
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.MalformedURLException;
>
> import javax.xml.parsers.ParserConfigurationException;
>
> import org.geotools.data.DefaultTransaction;
> import org.geotools.data.FeatureStore;
> import org.geotools.data.Transaction;
> import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;
> import org.geotools.factory.GeoTools;
> import org.geotools.feature.FeatureCollection;
> import org.geotools.feature.FeatureCollections;
> import org.geotools.feature.simple.SimpleFeatureBuilder;
> import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
> import org.geotools.gml3.v3_2.GMLConfiguration;
> import org.geotools.referencing.crs.DefaultGeographicCRS;
> import org.geotools.xml.StreamingParser;
> import org.opengis.feature.Property;
> import org.opengis.feature.simple.SimpleFeature;
> import org.opengis.feature.simple.SimpleFeatureType;
> import org.opengis.feature.type.AttributeType;
> import org.opengis.feature.type.PropertyType;
> import org.xml.sax.SAXException;
>
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.transform.stream.StreamResult;
>
> import org.w3c.dom.Document;
>
> public class GmlToShape {
>
>    public static void main(String[] args) {
>        try {
>            testWithSchema();
>        } catch (Exception e) {
>            // TODO Auto-generated catch block
>            e.printStackTrace();
>        }
>    }
>
>    public static void testWithSchema() throws Exception {
>        DocumentBuilder db =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
>
>        InputStream is = new FileInputStream("KsjAppSchema-A02_b.xsd" );
>        Document schema = db.parse( is );
>        Transformer tx = TransformerFactory.newInstance().newTransformer();
>        tx.transform( new DOMSource( schema ) , new StreamResult(
> "KsjAppSchema-A02_b.xsd" ) );
>
>        //update the schemaLocation to point at the schema
>        Document instance = db.parse( new
> FileInputStream("A02-60M-13-b-5339.xml"));
>        instance.getDocumentElement().setAttribute( "schemaLocation",
>            "http://nlftp.mlit.go.jp/ksj/schemas/ksj-app
> KsjAppSchema-A02_b.xsd");
>
>        tx.transform( new DOMSource( instance ), new StreamResult(
> "KsjAppSchema-A02_b.xsd" ) );
>
>        InputStream in = new FileInputStream( "KsjAppSchema-A02_b.xsd" );
>        GMLConfiguration gml = new GMLConfiguration();
>        StreamingParser parser = new StreamingParser( gml, in,
> SimpleFeature.class );
>
>    }
> }
>
> I upload the gml and xsd file.. please use this as test data.
>
> http://osgeo-org.1803224.n2.nabble.com/file/n5541451/A02-60M-13-b-5339.xml
> A02-60M-13-b-5339.xml
>
>
> http://osgeo-org.1803224.n2.nabble.com/file/n5541451/KsjAppSchema-A02_b-v1_0.xsd
> KsjAppSchema-A02_b-v1_0.xsd
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/how-to-solve-org-xml-sax-saxparseexception-premature-end-of-file-tp5541451p5541451.html
> Sent from the geotools-gt2-users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>



-- 
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to