Question

The problem I'm trying to solve is related to interaction between OpenLayers and TinyOWS, namely inserting a new feature, but I won't post any Javascript code or TinyOWS configs here because they are not relevant to the xml validation issue. I've tried to isolate problem as much as possible. Here is python2 code using lxml library for XML validation against schema:

from lxml import etree
from StringIO import StringIO

parser = etree.XMLParser(no_network=False)
etree.set_default_parser(parser)

schema_doc = etree.parse(StringIO('''\
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:tows="http://www.tinyows.org/" targetNamespace="http://www.tinyows.org/" elementFormDefault="qualified" version="1.1">
<xs:import namespace="http://www.opengis.net/wfs" schemaLocation="http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"/>
<xs:element name="cities" type="tows:citiesType" substitutionGroup="gml:_Feature"/>
<xs:complexType name="citiesType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="type_id" type="int" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="properties" type="string" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="geom" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
'''))

xml = etree.parse(StringIO('''\
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs">
<wfs:Insert>
<feature:cities xmlns:feature="http://www.tinyows.org">
<feature:geom>
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
<gml:pos>37.935083007812 55.4423828125</gml:pos>
</gml:Point>
</feature:geom>
</feature:cities>
</wfs:Insert>
</wfs:Transaction>'''))

schema = etree.XMLSchema(schema_doc)
schema.assertValid(xml)

Here I get the error:

lxml.etree.DocumentInvalid: Element '{http://www.tinyows.org}cities': This element is  not expected. Expected is one of ( {http://www.opengis.net/gml}_Feature, http://www.opengis.net/gml}FeatureCollection, {http://www.opengis.net/gml}MultiPointCoverage, {http://www.opengis.net/gml}MultiCurveCoverage, {http://www.opengis.net/gml}MultiSurfaceCoverage, {http://www.opengis.net/gml}MultiSolidCoverage, {http://www.opengis.net/gml}GridCoverage, {http://www.opengis.net/gml}RectifiedGridCoverage, {http://www.opengis.net/gml}Observation, {http://www.opengis.net/gml}DirectedObservation )., line 3

That seems cryptic to me, because cities feature is defined to substitute for gml:_Feature in schema. Perhaps the answer should lie within http://schemas.opengis.net/wfs/1.1.0/wfs.xsd, but I can't grasp the logic of validation.

Was it helpful?

Solution

I found that the string <feature:cities xmlns:feature="http://www.tinyows.org"> was the root of all evil, namely, missing trailing slash in http://www.tinyows.org namespace. Changed it to <feature:cities xmlns:feature="http://www.tinyows.org/"> solved the problem. Every symbol matters!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top