开发者

What's xmlns:mstns in a XSD?

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

<?xml version="1.0" encoding="utf-8"?>
<x开发者_JAVA百科s: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">
...


That's an XML namespace declaration.

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.

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.

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.


It is just a XML namespace. It is used as a prefix before tags. I guess the mstns is added by Microsoft's XML Serializer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜