0

我要解决的问题与 OpenLayers 和 TinyOWS 之间的交互有关,即插入新功能,但我不会在此处发布任何 Javascript 代码或 TinyOWS 配置,因为它们与 xml 验证问题无关。我试图尽可能地隔离问题。这是使用 lxml 库对模式进行 XML 验证的 python2 代码:

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)

在这里我得到错误:

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

这对我来说似乎很神秘,因为cities特性被定义为gml:_Feature在模式中替代。也许答案应该在http://schemas.opengis.net/wfs/1.1.0/wfs.xsd之内,但我无法掌握验证的逻辑。

4

1 回答 1

0

我发现字符串<feature:cities xmlns:feature="http://www.tinyows.org">是万恶之源,即http://www.tinyows.org命名空间中缺少斜杠。更改它以<feature:cities xmlns:feature="http://www.tinyows.org/">解决问题。每个符号都很重要!

于 2012-11-16T11:08:11.687 回答