Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JAXBElement is used to preserve the element name/namespace in use cases where enough information is not present in the object model. The most common occurence is with substitution groups:</p> <p><strong>With Substitution Group:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org" xmlns="http://www.example.org" elementFormDefault="qualified"&gt; &lt;xs:element name="root"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="anElement"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="anElement" type="xs:string"/&gt; &lt;xs:element name="aSubstituteElement" type="xs:string" substitutionGroup="anElement"/&gt; &lt;/xs:schema&gt; </code></pre> <p>Will generate:</p> <pre><code>package org.example; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "anElement" }) @XmlRootElement(name = "root") public class Root { @XmlElementRef(name = "anElement", namespace = "http://www.example.org", type = JAXBElement.class) protected JAXBElement&lt;String&gt; anElement; public JAXBElement&lt;String&gt; getAnElement() { return anElement; } public void setAnElement(JAXBElement&lt;String&gt; value) { this.anElement = ((JAXBElement&lt;String&gt; ) value); } } </code></pre> <p><strong>Without Substitution Group:</strong></p> <p>If you remove the substitution group:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org" xmlns="http://www.example.org" elementFormDefault="qualified"&gt; &lt;xs:element name="root"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="anElement"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="anElement" type="xs:string"/&gt; &lt;/xs:schema&gt; </code></pre> <p>The following class will be generated:</p> <pre><code>package org.example; import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "anElement" }) @XmlRootElement(name = "root") public class Root { @XmlElement(required = true) protected String anElement; public String getAnElement() { return anElement; } public void setAnElement(String value) { this.anElement = value; } } </code></pre> <p>You may also get a JAXBElement when you unmarshal, compare the following examples:</p> <ul> <li><a href="http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/TheBasics" rel="noreferrer">Without any JAXB metada the result will be wrapped in a JAXBElement</a></li> <li><a href="http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/JAXBCustomizations" rel="noreferrer">Using @XmlRootElement eliminates the root level JAXBElement</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload