Annotation Interface XmlRootElement


@Retention(RUNTIME) @Target(TYPE) public @interface XmlRootElement
Maps a class or an enum type to an XML element.

Usage

The XmlRootElement annotation can be used with the following program elements:

  • a top level class
  • an enum type

See "Package Specification" in jakarta.xml.bind.package javadoc for additional common information.

When a top level class or an enum type is annotated with the XmlRootElement annotation, then its value is represented as XML element in an XML document.

This annotation can be used with the following annotations: XmlType, XmlEnum, XmlAccessorType, XmlAccessorOrder.

Example 1: Associate an element with XML Schema type The annotation causes a global element declaration to be produced in the schema. The global element declaration is associated with the XML schema type to which the class is mapped.

Example 2: Orthogonality to type inheritance

An element declaration annotated on a type is not inherited by its derived types. The following example shows this. Example 3: Associate a global element with XML Schema type to which the class is mapped.

Since:
1.6, JAXB 2.0
Author:
Sekhar Vajjhala, Sun Microsystems, Inc.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    local name of the XML element.
    namespace name of the XML element.
  • Element Details

    • namespace

      String namespace
      namespace name of the XML element.

      If the value is "##default", then the XML namespace name is derived from the package of the class ( XmlSchema ). If the package is unnamed, then the XML namespace is the default empty namespace.

      Default:
      "##default"
    • name

      String name
      local name of the XML element.

      If the value is "##default", then the name is derived from the class name.

      Default:
      "##default"