Java xml element type

Java xml element type

A JavaBean property, when annotated with @XmlElement annotation is mapped to a local element in the XML Schema complex type to which the containing class is mapped.

Example 1: Map a public non static non final field to local element

//Example: Code fragment public class USPrice < @XmlElement(name="itemprice") public java.math.BigDecimal price; >      

Example 2: Map a field to a nillable element.

//Example: Code fragment public class USPrice < @XmlElement(nillable=true) public java.math.BigDecimal price; >      

Example 3: Map a field to a nillable, required element.

//Example: Code fragment public class USPrice < @XmlElement(nillable=true, required=true) public java.math.BigDecimal price; >      

Example 4: Map a JavaBean property to an XML element with anonymous type.

Optional Element Summary

Element Detail

name

Name of the XML Schema element. If the value is «##default», then element name is derived from the JavaBean property name.

nillable

public abstract boolean nillable

Customize the element declaration to be nillable. If nillable() is true, then the JavaBean property is mapped to a XML Schema nillable element declaration.

required

public abstract boolean required

Customize the element declaration to be required. If required() is true, then Javabean property is mapped to an XML schema element declaration with minOccurs=»1″. maxOccurs is «1» for a single valued property and «unbounded» for a multivalued property. If required() is false, then the Javabean property is mapped to XML Schema element declaration with minOccurs=»0″. maxOccurs is «1» for a single valued property and «unbounded» for a multivalued property.

Читайте также:  Заполнить массив строк java

namespace

  1. If the enclosing package has XmlSchema annotation, and its elementFormDefault is QUALIFIED , then the namespace of the enclosing class.
  2. Otherwise » (which produces unqualified element in the default namespace.

defaultValue

Источник

Java xml element type

A JavaBean property, when annotated with @XmlElement annotation is mapped to a local element in the XML Schema complex type to which the containing class is mapped.

Example 1: Map a public non static non final field to local element

//Example: Code fragment public class USPrice < @XmlElement(name="itemprice") public java.math.BigDecimal price; >      

Example 2: Map a field to a nillable element.

//Example: Code fragment public class USPrice < @XmlElement(nillable=true) public java.math.BigDecimal price; >      

Example 3: Map a field to a nillable, required element.

//Example: Code fragment public class USPrice < @XmlElement(nillable=true, required=true) public java.math.BigDecimal price; >      

Example 4: Map a JavaBean property to an XML element with anonymous type.

Optional Element Summary

Element Detail

name

Name of the XML Schema element. If the value is «##default», then element name is derived from the JavaBean property name.

nillable

public abstract boolean nillable

Customize the element declaration to be nillable. If nillable() is true, then the JavaBean property is mapped to a XML Schema nillable element declaration.

required

public abstract boolean required

Customize the element declaration to be required. If required() is true, then Javabean property is mapped to an XML schema element declaration with minOccurs=»1″. maxOccurs is «1» for a single valued property and «unbounded» for a multivalued property. If required() is false, then the Javabean property is mapped to XML Schema element declaration with minOccurs=»0″. maxOccurs is «1» for a single valued property and «unbounded» for a multivalued property.

namespace

  1. If the enclosing package has XmlSchema annotation, and its elementFormDefault is QUALIFIED , then the namespace of the enclosing class.
  2. Otherwise » (which produces unqualified element in the default namespace.

defaultValue

value specified as a default of this annotation element is used as a poor-man’s substitute for null to allow implementations to recognize the ‘no default value’ state.

type

Источник

Java xml element type

Determines whether the Node.appendChild operation would make this document not compliant with the VAL_INCOMPLETE validity type.

Determines whether the Node.insertBefore operation would make this document not compliant with the VAL_INCOMPLETE validity type.

Determines whether the Node.removeChild operation would make this document not compliant with the VAL_INCOMPLETE validity type.

Determines whether the Node.replaceChild operation would make this document not compliant with the VAL_INCOMPLETE validity type.

Determines if the attribute with given namespace and qualified name can be created if not already present in the attribute list of the element.

A NameList , as described in [DOM Level 3 Core] , of all possible attribute information items or wildcards that can appear as attributes of this element, or null if this element has no context or schema.

A NameList , as described in [ DOM Level 3 Core], of all possible element information items or wildcards that can appear as children of this element, or null if this element has no context or schema.

A NameList , as described in [ DOM Level 3 Core] , of all possible element information items or wildcards that can appear as a first child of this element, or null if this element has no context or schema.

A NameList , as described in [ DOM Level 3 Core] , of all possible element information items or wildcards that can appear as a next sibling of this element, or null if this element has no context or schema.

A NameList , as described in [ DOM Level 3 Core] , of all possible element information items that can appear as a parent this element, or null if this element has no context or schema.

A NameList , as described in [ DOM Level 3 Core] , of all possible element information items or wildcards that can appear as a previous sibling of this element, or null if this element has no context or schema.

Источник

Java xml element type

Maps a JavaBean property to a XML element derived from property’s type. Usage @XmlElementRef annotation can be used with a JavaBean property or from within XmlElementRefs This annotation dynamically associates an XML element name with the JavaBean property. When a JavaBean property is annotated with XmlElement , the XML element name is statically derived from the JavaBean property name. However, when this annotation is used, the XML element name is derived from the instance of the type of the JavaBean property at runtime.

XML Schema substitution group support

XML Schema allows a XML document author to use XML element names that were not statically specified in the content model of a schema using substitution groups. Schema derived code provides support for substitution groups using an element property, (section 5.5.5, «Element Property» of JAXB 2.0 specification). An element property method signature is of the form:

public void setTerm(JAXBElement); public JAXBElement getTerm();
  • If the collection item type (for collection property) or property type (for single valued property) is JAXBElement , then @XmlElementRef>.name() and @XmlElementRef.namespace() must point an element factory method with an @XmlElementDecl annotation in a class annotated with @XmlRegistry (usually ObjectFactory class generated by the schema compiler) :
    • @XmlElementDecl.name() must equal @XmlElementRef.name()
    • @XmlElementDecl.namespace() must equal @XmlElementRef.namespace().

    @XmlRootElement(name=»target») class Target < // The presence of @XmlElementRef indicates that the XML // element name will be derived from the @XmlRootElement // annotation on the type (for e.g. "jar" for JarTask). @XmlElementRef Listtasks; > abstract class Task < >@XmlRootElement(name=»jar») class JarTask extends Task < . >@XmlRootElement(name=»javac») class JavacTask extends Task < . >

    Target target = new Target(); target.tasks.add(new JarTask()); target.tasks.add(new JavacTask()); marshal(target);

    It is not an error to have a class that extends Task that doesn’t have XmlRootElement . But they can’t show up in an XML instance (because they don’t have XML element names). Example 2: XML Schema Susbstitution group support The following example shows the annotations for XML Schema substitution groups. The annotations and the ObjectFactory are derived from the schema.

    @XmlElement class Math < // The value of type()is // JAXBElement.class , which indicates the XML // element name ObjectFactory — in general a class marked // with @XmlRegistry. (See ObjectFactory below) // // The name() is «operator», a pointer to a // factory method annotated with a // XmlElementDecl with the name «operator». Since // «operator» is the head of a substitution group that // contains elements «add» and «sub» elements, «operator» // element can be substituted in an instance document by // elements «add» or «sub». At runtime, JAXBElement // instance contains the element name that has been // substituted in the XML document. // @XmlElementRef(type=JAXBElement.class,name=»operator») JAXBElement term; > @XmlRegistry class ObjectFactory < @XmlElementDecl(name="operator") JAXBElementcreateOperator(Operator o) @XmlElementDecl(name="add",substitutionHeadName="operator") JAXBElement createAdd(Operator o) @XmlElementDecl(name="sub",substitutionHeadName="operator") JAXBElement createSub(Operator o) > class Operator

    Math m = new Math(); m.term = new ObjectFactory().createAdd(new Operator()); marshal(m);

    Optional Element Summary

    Источник

Оцените статью