我试图解决的问题与OpenLayers和TinyOWS之间的交互有关,即插入一个新特性,但我不会在这里发布任何Javascript代码或TinyOWS配置,因为它们与xml验证问题无关。我已经试着尽可能地隔离问题。下面是使用lxml库对模式进行python2验证的XML代码:
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中,但我不能掌握验证的逻辑。
发布于 2012-11-16 19:08:12
我发现字符串<feature:cities xmlns:feature="http://www.tinyows.org">是所有错误的根源,即在http://www.tinyows.org名称空间中缺少尾随斜杠。将其更改为<feature:cities xmlns:feature="http://www.tinyows.org/">解决了问题。每一个符号都很重要!
https://stackoverflow.com/questions/13402156
复制相似问题