XML Namespaces

J2XB Supports multiple namespaces and XML Schema import automatically. When defining XML types and XML elements, we have the control of the namespace for our classes.

By default, the namespace for a Java class is generated from the class package. However, using the @MOXmlNamespace and @MOXmlNamespaceRef annotations is it possible to specify the exact namespace to use.

The @MOXmlNamespace has members for the namespace a prefered prefix. J2XB will try to use this prefix in XML documents and will do so unless there are conflicts. It usage is as

@MOXmlNamespace(value = "http://example.abra.com/helloWorld", preferedPrefix = "ex1")

The @MOXmlNamespaceRef has one member for a Class type. It defines that the namespace be read from that class. For instance, if we have the class HelloWorld defined with the above @MOXmlNamespace annotation, the following is equivalent to repeating the line above: