HOPEX UML : HOPEX XML Schemas : XSD Generation : Declaring Attributes (XSD)
   
Declaring Attributes (XSD)
 
Modeling XSD attributes
Attribute References (XSD)
"ID" Attributes (XSD)
Associations without Composition (XSD)
Attribute declarations indicate the presence of attributes in a tag type. Similarly to element declarations, constraints can be applied to attributes:
optional or required
default value
etc.
Modeling XSD attributes
UML attributes for classes correspond to attributes for tag types. To add an attribute declaration to a tag type, you must create an attribute in the class. The attribute type for the tag is inferred from the type of the UML attribute.
The schema editor enables you to parameterize the attribute declarations.
*Select the attribute in the navigator. The attribute properties dialog box is displayed in the left part of the editor.
XSD tab:
XSD Name: name of the attribute in the context of XSD generation. If this parameter is not specified, the attribute name is used for the generation.
XSD Id: used to identify the <attribute> tag.
XSD Form: gives the value of the "form" attribute.
XDD UML Attribute as XML element: specify if UML attributes are generated as XML elements or if they are generated according to their base type. Two options are available:
Determined from the base type: if the attribute type is simple, an XML attribute is generated. If the attribute type is complex, an XML element is generated.
Enforced as element: the UML attribute is generated as an XML element, whatever the base type is.
Characteristics tab:
Multiplicity: determines the value of the "use" attribute in the attribute declaration. The multiplicity can have the values "0", "0..1", or "1". The default multiplicity is "1".
If multiplicity = "0", "use" = "prohibited".
If multiplicity = "0..1", "use" = "optional".
If multiplicity = "1", "use" = "required".
Editable: when this attribute is set to "no", a "fixed" attribute appears in the <attribute> tag (if a value is specified for the Initial value parameter).
Initial value: if "Modifiable" is "no", the "fixed" attribute is generated and given the value contained in "Initial value". Otherwise a "default" attribute is generated, its value that of "Initial value".
Attribute References (XSD)
Just as you can make global element declarations, you can declare attributes at the schema level. These declarations are used in the types as references.
<XSD:attribute name="globAttribute" type="globType"/>
 
<XSD:complexType name="cType">
<XSD:attribute ref="globAttribute"/>
</xsd:complexType>
See "Referencing an Attribute (XML Schema)".
"ID" Attributes (XSD)
"ID" attributes provide a way to identify elements uniquely throughout the entire document.
By default, complex types are generated with "ID" attributes. This comes from the fact that the classes have the "XDD compulsory ID Attribute" generation parameter set to "yes". This parameter causes the generation of an "ID" attribute, its name specified by the "XDD ID Attribute Name" parameter, and whether it must be used specified by the "XDD ID Attribute Required" parameter.
*You can modify the parameters of all classes in a package by changing the parameters of the package itself.
When a UML attribute of the "ID" expression type is present for the class, the parameters specified in the Generation tab are ignored. There should not be more than one attribute of type "ID" for a class.
Associations without Composition (XSD)
"Simple" associations (associations without composition) are not interpreted as element declarations. When an association connects two classes, the navigable roles indicate that the class opposite the navigable role references the adjacent class. This is indicated by creating an attribute of type "IDREF" in the type corresponding to the "referencing" class.
The name of the generated attribute is taken from the name of the role. The multiplicity of the role also determines how the attribute is generated:
Multiplicity = "0", "use" = "prohibited"
Multiplicity = "0..1", "use" = "optional"
Multiplicity = "1", "use" = "required"
Multiplicity > of 1, the attribute type is "IDREFS"
<xsd:complexType name="Type2" mixed="false">
<xsd:attribute name="id" use="required" type="xsd:ID"/>
<xsd:attribute name="Referencedelements" use="optional" type="xsd:IDREFS"/>
</xsd:complexType>