Most XML documents are qualified with a namespace. You can namespace-qualify elements of your Java class at the following levels:

+

−

+

−

* Package

+

−

* Type

+

−

* Field / Property

+

−

+

−

+

−

In most cases, package-level annotation is sufficient. You can use the other levels to customize your document. Use the the '''@XmlSchema''' annotation to specify the namespace.

+

−

+

−

+

−

== Package Level ==

+

−

+

−

Use the '''@XmlSchema''' annotation on the package to set a default namespace and specify that all elements in the package are qualified with the namespace. This information is specified in a special Java source file, '''package-info.java'''.

+

−

+

−

<source lang="java">

+

−

@XmlSchema(

+

−

namespace="http://www.example.org/package",

+

−

elementFormDefault=XmlNsForm.QUALIFIED)

+

−

package example;

+

−

+

−

import javax.xml.bind.annotation.XmlNsForm;

+

−

import javax.xml.bind.annotation.XmlSchema;

+

−

</source>

+

−

+

−

Using a simple '''Customer''' class, this will produce the following XML:

+

−

+

−

<source lang="xml">

+

−

<customer xmlns="http://www.example.org/package">

+

−

<name>Jane Doe</name>

+

−

<account>36328721</account>

+

−

</customer>

+

−

</source>

+

−

+

−

All elements are qualified with the "<tt><nowiki>http://www.example.org/package</nowiki></tt>" namespace.