12

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">
...
leiflundgren
  • 2,876
  • 7
  • 35
  • 53
  • 2
    It defines an XML namespace `"http://tempuri.org/config.xsd"` and assigns it a prefix of `mstns` – marc_s Feb 17 '11 at 09:49

2 Answers2

11

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.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • 1
    Prefixes are arbitrary names (no colons, usual XML basic name rules). – Donal Fellows Feb 17 '11 at 10:07
  • 5
    And what about this exact namespace (mstns)? Does it have any special meaning in Visual Studio or .NET ? (It's declared by default in all schema files created in Visual Studio.) – kubal5003 Aug 23 '11 at 17:05
  • @kubal5003: The `mstns` _prefix_ has, to my knowledge, no special meaning. Prefixes are arbitrary (well, they're arbitrary NCNames in XML parlance). VS might assign special meaning to it I suppose, but probably not; Microsoft's tools have a habit of putting “ms” in all sorts of arbitrary generated names. (The URI that is the actual _logical name_ of the namespace can have all sorts of semantics associated with it, but I don't think you're asking about that.) – Donal Fellows Nov 22 '11 at 09:33
  • Thinking about it a bit more, “mstns” is the prefix “ms” (gee, MicroSoft loves to get in there somewhere!) followed by “tns” which normally stands for “target namespace”, which is the namespace in which you're declaring elements. In other words, it really doesn't mean very much in itself… – Donal Fellows Feb 05 '13 at 14:13
2

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.

Vagmi Mudumbai
  • 613
  • 8
  • 14