XSD架构目标命名空间

时间:2012-11-15 08:32:41

标签: xml namespaces schema gml ogc

我正在尝试设置一个新的gml功能模式,但我认为我误解了命名空间。继承我的架构:

<xs:schema targetNamespace="http://localhost/dar" xmlns:gml="http://www.opengis.net/gml" xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns="http://localhost/dar">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd" />
<xs:element name="Region" substitutionGroup="gml:_Feature">
    <xs:complexType>
        <xs:complexContent>
            <xs:extension base="gml:AbstractFeatureType">
                <xs:sequence>
                    <xs:element name="regionId" type="xs:string" />
                    <xs:element name="regionName" type="xs:string" />
                    <xs:element ref="gml:Polygon" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:element>

继承我的测试xml doc:

<wfs:FeatureCollection xmlns="http://localhost/dar" xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://localhost/dar http://localhost/dar/DariusFeatures.xsd
http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<gml:boundedBy>
    <gml:Envelope srsName="http://www.opengis.net/gml/srs/epsg.xml#63266405">
        <gml:lowerCorner>10 10</gml:lowerCorner>
        <gml:upperCorner>20 20</gml:upperCorner>
    </gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
    <Region>
        <regionId>region432762</regionId>
        <regionName>Southern Block</regionName>
        <gml:Polygon>
            <gml:exterior>
                <gml:LinearRing>
                    <gml:coordinates>38.324,21.754 38.424,21.754 38.424,21.854 38.324,21.854 38.324,21.754 </gml:coordinates>
                </gml:LinearRing>
            </gml:exterior>
        </gml:Polygon>
    </Region>
</gml:featureMember>

现在架构在eclipse中验证正常但是当我尝试验证xml doc时,eclipse告诉我架构文件的目标Namespace是“null”吗?

可以看出,我已在localhost上部署了架构。 谁能看到我搞砸了哪里?

3 个答案:

答案 0 :(得分:1)

尝试将以下行添加到xml架构中:

<xs:import namespace="http://www.opengis.net/wfs" schemaLocation="http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" />

鉴于该行(和elementFormDefault =&#34;限定&#34;在xs:schema中,如Ian所说),xml应该验证。

答案 1 :(得分:0)

简短版:您需要将elementFormDefault="qualified"添加到xs:schema元素。

更长版本:默认情况下,只有架构中的顶级元素声明才会进入目标命名空间,嵌套在复杂类型中的元素不会声明为命名空间。因此,当前编写的模式要求regionNameregionId不在命名空间中,但是您的XML文档将它们放在http://localhost/dar命名空间中。 elementFormDefault导致嵌套的“本地”元素也会占用目标名称空间。

答案 2 :(得分:0)

好吧,它已经好几天了,验证问题仍然是个谜。 作为一种解决方法,我发现有一个更新版本的OGC的Web功能服务: http://schemas.opengis.net/wfs/2.0/wfs.xsd 它使用gml 3.2而不是gml 3.1.1

经过微小的改动后,使用这种新格式就好了!

相关问题