XSD 中的 xmlns:mstns 是什么? [英] What's xmlns:mstns in a XSD?

查看:42
本文介绍了XSD 中的 xmlns:mstns 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 xsd-header 中的 xml:mstns 表示什么?

What do the xml:mstns express in the following xsd-header?

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="config"
    targetNamespace="http:/tempuri.org/config.xsd"
    elementFormDefault="qualified"
    xmlns=""
    xmlns:mstns="http://tempuri.org/config.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:element name="config">
...

推荐答案

这是一个 XML 命名空间声明.

That's an XML namespace declaration.

XML 名称空间实际上是由 URI 定义的,因此限定名称由名称空间(任意 URI)和本地名称(遵循 NCName 规则的简短字符串)组成.然而,这不可能每次都完整写出,因此命名空间通过命名空间声明映射到前缀,该声明始终采用以 xmlns 开头的属性形式,并为包含它及其所有子元素的元素.

XML namespaces are really defined by URIs, so that a qualified name consists of a namespace (an arbitrary URI) and a local name (a short simple string following the NCName rules). However, that can't be written out in full every time, so namespaces are mapped to prefixes by a namespace declaration, which always takes the form of an attribute starting with xmlns and which defines that prefix for the element containing it and all its child elements.

让我们以您的案例为例.

Let's take your case as an example.

我们有一个属性 xmlns:mstns="http://tempuri.org/config.xsd",它只是说前缀 mstns 被映射到命名空间 URI http://tempuri.org/config.xsd;这意味着名称以 mstns:(注意冒号)开头的所有元素和属性都在该命名空间中.在您的示例中,我们还看到 xmlns="",它将所有元素(棘手点:不是属性!)映射到空 URI.

We have an attribute xmlns:mstns="http://tempuri.org/config.xsd", and that simply says that the prefix mstns is mapped to the namespace URI http://tempuri.org/config.xsd; this means that all elements and attributes whose names start with mstns: (note the colon) are in that namespace. In your example we also see xmlns="", which maps all elements (tricky point: not attributes!) without prefix to the empty URI.

显然,您不能使用 xmlns 本身作为前缀(这很神奇),实际上所有以 xml 开头的前缀都是保留的.在模式中使用 tns 前缀来指示目标命名空间是一个常见的习惯.

Obviously, you can't use xmlns itself as a prefix (it's magical) and in fact all prefixes starting with xml are reserved. There's a common habit of using the tns prefix in schemas to indicate the Target NameSpace.

这篇关于XSD 中的 xmlns:mstns 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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