Default Namespaces

Contact Us or call 1-877-932-8228
Default Namespaces

Default Namespaces

Let's consider the Artist.xsd schema for a moment. The first thing to remember is that the XML schema document is itself an instance document. The xmlns attributes are used to indicate what namespaces are associated with this instance.

The xs:schema element looks like this:

<xs:schema xmlns:xs="" xmlns="" targetNamespace="">

The xmlns:xs attribute indicates that global elements, attributes, types, and groups in the XML Schema namespace can be used in this document, but they must be qualified with the xs: prefix.

Note that you could change this prefix to bob: or jill:, though xs: and xsd: are the most commonly used for the XML Schema namespace.

The second xmlns attribute indicates that global elements, attributes, types, and groups in the Artist namespace can be used in this document without a prefix (i.e, unqualified). The Artist namespace then is the default namespace. There can only be one default namespace in an instance document.

Now let's look at the MichaelJackson.xml instance document.

<Artist BirthYear="1958" xmlns:xsi="" xmlns="" xsi:schemaLocation=" Artist.xsd">

It uses two namespaces:, which we will discuss later, and

Notice that none of the elements or attributes in the document is qualified (i.e, prefixed). That is because they all belong to the Artist namespace, which is the default namespace. The sample code below shows how this same document would look without a default namespace.

Code Sample:

<?xml version="1.0"?>
<art:Artist BirthYear="1958"
			xsi:schemaLocation=" Artist.xsd">

Generally, it only makes sense to use qualifiers when using more than one namespace.