XML Schema import -vs- 命名空间绑定到前缀 [英] XML Schema import -vs- namespaces bound to prefixes

查看:22
本文介绍了XML Schema import -vs- 命名空间绑定到前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 XML 架构的新手,我遇到了架构文档,这些文档将多个前缀绑定到 xsd:schema 根元素中的各种命名空间,并且还导入了一个子集这样的模式.在 XML Schema 文档的其余部分中,他们愉快地使用了 xsd:schema 元素(无论是否导入)中绑定的所有前缀.

I am new to XML Schema and am coming across schema documents that bind a number of prefixes to various namespaces in the xsd:schema root element and also import a subset of such schemas. In the rest of the XML Schema document they happily make use of all prefixes bound in the xsd:schema element (whether imported or not).

那么,命名空间的 import 比只是"将该命名空间绑定到前缀意味着什么?

So what does an import of a namespace signify over 'just' binding that namespace to a prefix?

从我读过的 Definitive XML Schema 一书中(第 66 页):

From the Definitive XML Schema book I read (pg. 66):

导入用于告诉处理器您将引用来自其他命名空间的组件

在我的理解中,这也是绑定的作用,那么有什么区别?

In my understanding, that's also what a binding does, so what's the difference?

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:vr="http://www.ivoa.net/xml/VOResource/v1.0"
           xmlns:ssap="http://www.ivoa.net/xml/SSA/v1.0"
           xmlns:vm="http://www.ivoa.net/xml/VOMetadata/v0.1"
           targetNamespace="http://www.ivoa.net/xml/SSA/v1.0"
           elementFormDefault="unqualified" 
           attributeFormDefault="unqualified"
           version="1.0pr2">


   <xs:import namespace="http://www.ivoa.net/xml/VOResource/v1.0"
         schemaLocation="http://www.ivoa.net/xml/VOResource/v1.0"/>

   <!--  ... rest of the schema document follows -->

上面模式文档中的

Namespace http://www.ivoa.net/xml/VOResource/v1.0 都绑定到vr 前缀并导入.其他命名空间仅绑定到某些前缀而不是导入.文档的其余部分使用来自 vr(绑定和导入)和 ssa(绑定但未导入)前缀的组件.有什么区别?

Namespace http://www.ivoa.net/xml/VOResource/v1.0 in the above schema document is both bound to the vr prefix and imported. Other namespaces are only bound to certain prefixes and not imported. The rest of the document uses components from both vr (bound and imported) and ssa (bound but not imported) prefixes. What's the difference?

推荐答案

如果有对组件的引用,例如 vr:someType,则:

If there's a reference to a component such as vr:someType, then :

  1. 您需要命名空间声明,以便处理器知道vr 引用的命名空间

您需要导入声明,以便处理器知道在哪里可以找到组件 vr:someType

you need the import declaration so the processor knows where to find the component vr:someType

这有点简化.理论上,导入不会告诉处理器在哪里查看;schemaLocation 只是一个提示".实际上,对于大多数处理器,schemaLocation 要么是模式文档的实际位置,要么是可以重定向(例如使用目录)到实际位置的 URI.

That's a bit of a simplification. In theory the import doesn't tell the processor where to look; the schemaLocation is only a "hint". In practice for most processors the schemaLocation is either the actual location of a schema document, or a URI that can be redirected (e.g. using a catalog) to the actual location.

规范可能允许诸如 vr:someType 之类的引用在没有导入的情况下存在,依赖于实现定义的机制来定位特定命名空间的架构组件.但它不允许这样做.

The specification could have permitted references such as vr:someType to exist without the import, relying on implementation-defined mechanisms to locate schema components for a particular namespace. But it doesn't permit this.

这篇关于XML Schema import -vs- 命名空间绑定到前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆