Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's xmlns:mstns in a XSD?

Tags:

xml

xsd

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">
...
like image 735
leiflundgren Avatar asked Feb 17 '11 09:02

leiflundgren


2 Answers

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.

like image 77
Donal Fellows Avatar answered Nov 19 '22 15:11

Donal Fellows


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.

like image 38
Vagmi Mudumbai Avatar answered Nov 19 '22 14:11

Vagmi Mudumbai