Validating KML using Native Java Libraries

255 views
Skip to first unread message

rws5066

unread,
Jun 17, 2009, 9:48:21 AM6/17/09
to KML Developer Support - Getting Started with KML
Hey -

I've been looking for this subject already posted and wasn't able to
find it so sorry if I'm reposting...

I'm attempting to validate Google Earth Generated KMLs along with
custom KMLs. I know jedit is out there, but I am attempting to do this
within java in a custom app.

I can validate our custom KMLs, but oddly my problem is validating
Google Earth generated KMLs. For validation I'm using the tried and
true javax.xml library.

SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/
2001/XMLSchema");
Schema schema = factory.newSchema(new URL("http://code.google.com/apis/
kml/schema/kml22beta.xsd"));
Validator validator = schema.newValidator();
Source source = new StreamSource(inputFile);
validator.validate(source);

Running this produces constant Validation errors regardless of any
Google Earth Generated KML passed in, any Ideas ?

Roman N

unread,
Jun 19, 2009, 5:16:53 PM6/19/09
to KML Developer Support - Getting Started with KML
Hi rws5066,

Make sure you're using the correct new XSDs:

OGC KML 2.2: http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd
Google's KML extensions: http://code.google.com/apis/kml/schema/kml22gx.xsd

Also, I happen to have a full Java code snippet for validating KML, if
you need it.

Thanks,
Roman

Azazelo

unread,
Jun 23, 2009, 8:57:40 AM6/23/09
to KML Developer Support - Getting Started with KML
Hi,
I am struggling with the same issue but I keep encountering problems
when validating with JAXP (declaration of kml can not be found even
though I use the right schemas and setting the schema source is done
properly).
Can you please send me the code snippet for validating KML?
Thank you,
Isabela

Roman N

unread,
Jun 26, 2009, 5:53:47 PM6/26/09
to KML Developer Support - Getting Started with KML
Hi Isabela,

Sure, I put the KML validation servlet Java code here:

http://code.google.com/p/kml-samples/source/browse/trunk/utils/KmlValidatorServlet.java

You'll probably only need a small chunk of that code though, as a lot
of it is servlet-specific.

Thanks,
Roman
Reply all
Reply to author
Forward
0 new messages