HOPEX UML : HOPEX XML Schemas : Creating an XML Schema : Defining attributes
   
Defining attributes
 
Creating an Attribute in an XML Schema
Result
UML modeling
Attribute Characteristics
Attribute type
Initial value
Multiplicity
Static
UML modeling
The XML attributes of a tag are pairs of strings in the format name-value. The second string is contained within quotes. XML attributes serve to characterize the tag. Example: <person name= ’Smith’/>
An attribute can only contain information related to its value.
Creating an Attribute in an XML Schema
To create a new attribute:
1. Select the element for which you wish to create a new attribute, then click the Create Attribute button in the editor toolbar.
The properties dialog box for the attribute appears.
2. Enter the name of the attribute and click OK.
The attribute is created.
Result
 
Diagram
Diagram
XML Document
<person name= "Smith"/>
UML modeling
To add attributes:
1. Open the Properties dialog box of the class for which you wish to create an attibute (pop-up menu/Properties).
2. In the Attributes tab, click the New button
3. Enter the name of the attribute and click OK.
 
Attribute Characteristics
To define attribute characteristics:
*Select the attribute on the left of the schema editor. The properties for the attribute will appear on the right.
*You can also access the properties dialog box by right-clicking the attribute and selecting Properties.
Attribute type
The ExpressionType allows you to define the type of attribute. The list that appears corresponds to common package types and referenced namespace types.
Initial value
Each attribute can have a default value. When a tag does not define an optional attribute, if the attribute has a default value, this value will be assigned to it automatically.
To define a default value:
*Open the properties dialog box of the attribute.
*Click the Characteristics tab.
*In the Initial Value box, enter the default value.
Example
The collection class has a name attribute with an initial value of "SimonSchuster".
XSD
<xsd:ComplexType name="Collection">
<xsd:attribute name="name" default="SimonSchuster" use="required">
<xsd:SimpleType>
<xsd:restriction base='xsd:string'>
<xsd:enumeration value='SimonSchuster'/>
<xsd:enumeration value='RandomHouse'/>
<xsd:enumeration value='Bantam Books'/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:ComplexType>
Multiplicity
*The multiplicity of an attribute defines the number of occurrences of the attribute in a class.
In a schema, an attribute can only appear once (a Person has only one name for example). Multiplicities that can be specified are:
0: attribute not allowed,
0..1: optional,
1: required (default value).
*In the Multiplicity text box, select 0, 01 or 1.
*The 0 multiplicity is useful when a class inherits an undesired attribute: using the overloading function, it is possible to set the multiplicity of the attribute to 0 and therefore eliminate the attribute.
Static
It is possible to specify if the attribute can be modified. Static specifies if the attribute can take specific values for each instance of the class or take one value characterizing the entire class.
"Yes": the attribute has a value that characterizes the entire class. The attribute "Telephone number length" for the "USA Client" class is 10 digits.
"No": the attribute can take a different value for each class instance. For example, the "Telephone number" attribute has a different value for each instance of the "Client" class.
Example
For the Collection attribute, if the field is set to:
"Yes": the value of the Collection attribute cannot be modified.
"No": the "SimonSchuster" value can be changed to "RandomHouse" for example
"Add only": this parameter is not used in the context of XML schemas. If you select it, the attribute is considered as changeable.
UML modeling
To define the properties of an attribute:
1. Open the properties dialog box for the class (right-click it and select Properties) and select the Attributes tab.
2. Select the attribute concerned and click the Properties button :
The properties dialog box for the attribute appears.