Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Este conteúdo não está disponível no idioma selecionado.
33.2. Attributes
Overview Copiar o linkLink copiado para a área de transferência!
attribute
elements and attributeGroup
elements within the scope of a complexType
element. When defining structures for an XML document attribute declarations provide a means of adding information that is specified within the tag, not the value that the tag contains. For example, when describing the XML element <value currency="euro">410<\value> in XML Schema the currency
attribute is described using an attribute
element as shown in Example 33.5, “XML Schema Defining and Attribute”.
attributeGroup
element allows you to define a group of reusable attributes that can be referenced by all complex types defined by the schema. For example, if you are defining a series of elements that all use the attributes category
and pubDate
, you could define an attribute group with these attributes and reference them in all the elements that use them. This is shown in Example 33.7, “Attribute Group Definition”.
use
attribute is set to either optional
or required
are treated as elements of a structure. For each attribute declaration contained within a complex type description, an element is generated in the class for the attribute, along with the appropriate getter and setter methods.
Defining an attribute in XML Schema Copiar o linkLink copiado para a área de transferência!
attribute
element has one required attribute, name
, that is used to identify the attribute. It also has four optional attributes that are described in Table 33.2, “Optional Attributes Used to Define Attributes in XML Schema”.
Attribute | Description |
---|---|
use | Specifies if the attribute is required. Valid values are required , optional , or prohibited . optional is the default value. |
type | Specifies the type of value the attribute can take. If it is not used the schema type of the attribute must be defined in-line. |
default | Specifies a default value to use for the attribute. It is only used when the attribute element's use attribute is set to optional . |
fixed | Specifies a fixed value to use for the attribute. It is only used when the attribute element's use attribute is set to optional . |
Example 33.5. XML Schema Defining and Attribute
type
attribute is omitted from the attribute
element, the format of the data must be described in-line. Example 33.6, “Attribute with an In-Line Data Description” shows an attribute
element for an attribute, category
, that can take the values autobiography
, non-fiction
, or fiction
.
Example 33.6. Attribute with an In-Line Data Description
Using an attribute group in XML Schema Copiar o linkLink copiado para a área de transferência!
- Define the attribute group.An attribute group is defined using an
attributeGroup
element with a number ofattribute
child elements. TheattributeGroup
requires aname
attribute that defines the string used to refer to the attribute group. Theattribute
elements define the members of the attribute group and are specified as shown in the section called “Defining an attribute in XML Schema”. Example 33.7, “Attribute Group Definition” shows the description of the attribute groupcatalogIndecies
. The attribute group has two members:category
, which is optional, andpubDate
, which is required.Example 33.7. Attribute Group Definition
<attributeGroup name="catalogIndices"> <attribute name="category" type="catagoryType" /> <attribute name="pubDate" type="dateTime" use="required" /> </attributeGroup>
<attributeGroup name="catalogIndices"> <attribute name="category" type="catagoryType" /> <attribute name="pubDate" type="dateTime" use="required" /> </attributeGroup>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Use the attribute group in the definition of a complex type.You use attribute groups in complex type definitions by using the
attributeGroup
element with theref
attribute. The value of theref
attribute is the name given the attribute group that you want to use as part of the type definition. For example if you want to use the attribute groupcatalogIndecies
in the complex type dvdType, you would use <attributeGroup ref="catalogIndecies" /> as shown in Example 33.8, “Complex Type with an Attribute Group”.Example 33.8. Complex Type with an Attribute Group
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Mapping attributes to Java Copiar o linkLink copiado para a área de transferência!
@XmlAttribute
annotation. If the attribute is required, the @XmlAttribute
annotation's required property is set to true
.
Example 33.9. techDoc Description
Example 33.10. techDoc Java Class
default
attribute and the fixed
attribute instruct the code generators to add code to the getter method generated for the attribute. This additional code ensures that the specified value is returned if no value is set.
fixed
attribute is treated the same as the default
attribute. If you want the fixed
attribute to be treated as a Java constant you can use the customization described in Section 36.5, “Customizing Fixed Value Attribute Mapping”.
Mapping attribute groups to Java Copiar o linkLink copiado para a área de transferência!
category
and pubDate
to support the members of the attribute group as shown in Example 33.11, “dvdType Java Class”.
Example 33.11. dvdType Java Class