schema element validation

861 views
Skip to first unread message

tsteven4

unread,
Oct 16, 2010, 4:18:34 PM10/16/10
to kml-support-g...@googlegroups.com
googleexample.kml

Jason M

unread,
Oct 17, 2010, 6:38:25 PM10/17/10
to KML Developer Support - Getting Started with KML
The example fails because it violates the KML XML schema.
http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd

For example, the "Schema" element must be after the Style elements in
a Document.

And second, the order of style in wrong: IconStyle preceeds
LabelStyle.

<Style id="track_n">
<LabelStyle>
<scale>0</scale>
</LabelStyle>
<IconStyle>
<scale>.5</scale>
<Icon>
<href>http://earth.google.com/images/kml-icons/track-
directional/track-none.png</href>
</Icon>
</IconStyle>
</Style>

must be reordered:

<Style id="track_n">
<IconStyle>
<scale>.5</scale>
<Icon>
<href>http://earth.google.com/images/kml-icons/track-
directional/track-none.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<scale>0</scale>
</LabelStyle>
</Style>

There are a few similar errors in the file.

Example must be reordered as following:

<kml>
<Document>
<LookAt>...</LookAt>
<Style id="track_n">
...
</Style>
<Schema>.../Schema>
<Folder>..</Folder>
</Document>
</kml>

On Oct 16, 4:18 pm, tsteven4 wrote:
> The example herehttp://code.google.com/apis/kml/documentation/kmlreference.html#track...
>  googleexample.kml
> 5KViewDownload

Jason M

unread,
Oct 17, 2010, 6:52:11 PM10/17/10
to KML Developer Support - Getting Started with KML
Rewrote the example and posted in a bug report.
http://code.google.com/p/kml-samples/issues/detail?id=364

Valid example submitted as an attachment to the bug report.

tsteven4

unread,
Oct 18, 2010, 9:34:49 AM10/18/10
to KML Developer Support - Getting Started with KML
Can the Schema element be located after the final folder is closed and
before the document is closed? For example:

<kml>
<Document>
<LookAt>...</LookAt>
<Style id="track_n">
...
</Style>
<Folder>..</Folder>
<Schema>.../Schema>
</Document>
</kml>


This order does validate.

I believe I understand how the Document type definition would allow
elements from the AbstractContainerGroup (Folder, Document), which may
be substituted for the AbstractFeatureGroup, to be after the Schema
element as you have shown.

But from validation it appears Folder elements may also be before the
Schema element. It appears this must be due to the extension base,
but my understanding of how this order is allowed is lacking. Can you
explain this?

> <complexType name="DocumentType" final="#all">
> <complexContent>
> <extension base="kml:AbstractContainerType">
> <sequence>
> <element ref="kml:Schema" minOccurs="0" maxOccurs="unbounded"/>
> <element ref="kml:AbstractFeatureGroup" minOccurs="0" maxOccurs="unbounded"/>
> <element ref="kml:DocumentSimpleExtensionGroup" minOccurs="0" maxOccurs="unbounded"/>
> <element ref="kml:DocumentObjectExtensionGroup" minOccurs="0" maxOccurs="unbounded"/>
> </sequence>
> </extension>
> </complexContent>
> </complexType>


Thanks

On Oct 17, 4:52 pm, Jason M wrote:
> Rewrote the example and posted in a bug report.http://code.google.com/p/kml-samples/issues/detail?id=364

Jason M

unread,
Oct 18, 2010, 9:44:17 PM10/18/10
to KML Developer Support - Getting Started with KML
Hi,

You use xmllint to validate. Not sure if that is using the schemas
strictly by the spec. Maybe there are some lax options set by
default. Not sure. I use Xerces with a validating XML DOMParser
(e.g. org.apache.xerces.parsers.DOMParser).

If you rewrite the KML file with schemaLocation declaration then a
validating DOM/SAX parser can verify the document against the XML
schema.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/kml/2.2
http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd
http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd">
...
</kml>

Xerces with following SAX features set to true enables full schema
validation:

http://xml.org/sax/features/namespaces
http://xml.org/sax/features/validation
http://apache.org/xml/features/validation/schema
http://apache.org/xml/features/validation/schema-full-checking

If I reorder the KML such that the Schema follows the Folder the
validating DOM parser fails validation which is as expected.

AbstractFeatureGroup (including the Folder) must follow the Schema
elements.

ERROR: SAXParseException: cvc-complex-type.2.4.a: Invalid content was
found starting with element 'Schema'.
One of '{"http://www.opengis.net/kml/2.2":AbstractFeatureGroup,
"http://www.opengis.net/kml/2.2":DocumentSimpleExtensionGroup,
"http://www.opengis.net/kml/2.2":DocumentObjectExtensionGroup}' is
expected.
Line: 168, column: 25
168: <Schema id="schema">***

On Oct 18, 9:34 am, tsteven4 wrote:
> Can the Schema element be located after the final folder is closed and
> before the document is closed?  For example:
>
> <kml>
>   <Document>
>     <LookAt>...</LookAt>
>     <Style id="track_n">
> ...
>     </Style>
>   <Folder>..</Folder>
>   <Schema>.../Schema>
>   </Document>
> </kml>
>
> This order does validate.

--jason

tsteven4

unread,
Oct 21, 2010, 9:23:36 AM10/21/10
to KML Developer Support - Getting Started with KML
Jason,

Thanks for your help. I am glad the issue was not my understanding of
the kml xsd. As you reported the problem was with xmllint or the way
I was running xmllint.

Instead of running xmllint as follows, which does not detect the
error:
--schema http://code.google.com/apis/kml/schema/kml22gx.xsd dut.kml

I can show the validation errors with DOMCount from Xerces-C++ with
the following command line:

DOMCount -n -s -v=always -f dut.kml

I modified the DOMCount.cpp sample to hardcode the xsd locations for
kml so I don't have to edit dut.kml which doesn't include the schema
locations.

// enable datatype normalization - default is off
config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);

+ // set kml schema locations
+ XMLCh* nsloc=XMLString::transcode("http://www.opengis.net/kml/
http://code.google.com/apis/kml/schema/kml22gx.xsd");
+ config-
>setParameter(XMLUni::fgXercesSchemaExternalSchemaLocation, nsloc);
+
// And create our error handler and install it

This works with the following kml element:
It would be nice if DOMCount (*Count, *Counter) included an option
like xmllint's --schema option. It seems like a very popular subject
of discussion over the years. Any Xerces project contributors?

I have been unsuccessful so far in modifying samples/dom/Counter.java
from Xerces-J to do the same thing.

Thanks Again,
Steve

On Oct 18, 7:44 pm, Jason M wrote:
> Hi,
>
> You use xmllint to validate. Not sure if that is using the schemas
> strictly by the spec.  Maybe there are some lax options set by
> default.  Not sure.  I use Xerces with a validating XML DOMParser
> (e.g. org.apache.xerces.parsers.DOMParser).
>
> If you rewrite the KML file with schemaLocation declaration then a
> validating DOM/SAX parser can verify the document against the XML
> schema.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://www.opengis.net/kml/2.2"
>         xmlns:gx="http://www.google.com/kml/ext/2.2"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xsi:schemaLocation="http://www.opengis.net/kml/2.2http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd
>                        http://www.google.com/kml/ext/2.2http://code.google.com/apis/kml/schema/kml22gx.xsd">
Reply all
Reply to author
Forward
0 new messages