Eclipse has support for XML Schema so you can develop and test your own schemas for free!

If you are new to XML Schema, the XML Schema tutorial from is a good starter to enter the world of XML Schema.

Make sure you installed the necessary Web Tools Platform plug-ins so you have the necessary features to develop your schemas.

At the moment I’m using Eclipse version 3.7.1.

In Eclipse, create a new general project, in that project create a new XML Schema file. I called the file MySchema.xsd.

Ecplise starts with a nice template.

It makes already a target namespace for you, in this case
The target namespace is the unique namespace in which you declare your elements.
The purpose of a namespace is to prevent collisions, so if you declare an element bank (furniture) with a different content model as someone else, e.g. bank (financial institution), these elements can live together if they are in a different namespace. I will demonstrate such an example in a future article.

The target namespace here gets the prefix tns:.
The default namespace is used here for the XML Schema itself (referred with xmlns= without a prefix), so the elements in this namespace don’t have a prefix.

You also could have written:

  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <xs:schema xmlns:xs=""
  4.  targetNamespace=""
  5.  xmlns:tns="" elementFormDefault="qualified">
  6. </xs:schema>

The schema element is in the namespace and referred with the xs: prefix. This prefix is just an alias for the full namespace. So you can use whatever prefix you want.

So the schema element has to be in the namespace

If you write:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <schema xmlns:xs=""
  3.  targetNamespace=""
  4.  xmlns:tns="" elementFormDefault="qualified">
  5. </schema>

you will get an error while validating the schema (right click the filename and select “validate”):

  1. The namespace of element 'schema' must be from the schema namespace,
  2. ''.

Until now we don’t have declared any elements in our schema.
Let’s add one element to the schema:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <schema xmlns=""
  3.  targetNamespace=""
  4.  xmlns:tns="" elementFormDefault="qualified">
  5.  <element name="myRootElement"/>
  6. </schema>

Now let’s create an XML file based on this very basic schema.

And here we have the result:

We have the element myRootElement in the namespace referred to it with the prefix tns.

We refer to our schema with the attribute xsi:schemaLocation, the first value of the attribute is the target namespace, the second value is the filename location.

As you can see the attribute schemaLocation lives in its own namespace and is not part of the schema we made.

If we use as the default namespace the target namespace we can write:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <myRootElement
  3.  xmlns=""
  4.  xmlns:xsi=""
  5.  xsi:schemaLocation=" MySchema.xsd ">
  6. </myRootElement>
Rating 2.40 out of 5