【问题标题】:XSD schema target namespaceXSD 架构目标命名空间
【发布时间】:2012-11-03 20:03:42
【问题描述】:

我正在尝试设置一个新的 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 文档:

<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 文档时,Eclipse 告诉我架构文件的目标命名空间为“null”?

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

【问题讨论】:

  • 为什么架构根目录中有 xmlns="localhost/dar"?
  • 谢谢,不需要你的权利,但这不是问题,我已将其删除,但仍然出现相同的验证错误
  • 您的示例无效,您缺少结束 &lt;/wfs:FeatureCollection&gt; 标记。

标签: xml namespaces schema gml ogc


【解决方案1】:

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

加长版:默认情况下,只有架构中的顶级元素声明进入目标命名空间,嵌套在复杂类型中的元素不会声明到命名空间中。因此,当前编写的架构预计 regionNameregionId 不在命名空间中,但您的 XML 文档将它们放在 http://localhost/dar 命名空间中。 elementFormDefault 使嵌套的“本地”元素也采用目标命名空间。

【讨论】:

  • 这是有道理的,但是我将 elementFormDefault="qualified" 添加到 localhost/dar/DariusFeatures.xsd,刷新了 eclipse,但我仍然收到相同的验证错误,即目标命名空间为空,还有其他建议吗?
  • @user143278 我注意到你没有在xsi:schemaLocation 中列出http://www.opengis.net/gml 命名空间,也许这就是它所抱怨的。
  • 不需要,因为 schemas.opengis.net/wfs/1.1.0/wfs.xsd 在内部导入它
【解决方案2】:

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

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

鉴于该行(以及 xs:schema 中的 elementFormDefault="qualified",正如 Ian 所说),xml 应该验证。

【讨论】:

  • 对不起,没有帮助,我也看不出它有什么帮助,因为 _Feature 元素位于 gml 命名空间下,wfs 只是利用它
【解决方案3】:

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

在使用这种新格式的小改动后一切正常!

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 2010-10-19
    • 1970-01-01
    • 2014-02-04
    • 2015-04-14
    • 1970-01-01
    • 2010-12-23
    • 2013-07-14
    • 2012-06-01
    相关资源
    最近更新 更多