首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有WFS的xml :transaction/insert-request无法针对WFS xsd-schema进行验证

带有WFS的xml :transaction/insert-request无法针对WFS xsd-schema进行验证
EN

Stack Overflow用户
提问于 2012-11-16 00:39:48
回答 1查看 745关注 0票数 0

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

代码语言:javascript
复制
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)

下面是我得到的错误:

代码语言:javascript
复制
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中,但我不能掌握验证的逻辑。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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/">解决了问题。每一个符号都很重要!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13402156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档