Page History
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
|
...
...
...
...
...
...
...
...
...
...
...
UML properties having a simple type are mapped to XML attributes.
If the property type is complex, the compiler will report an error.
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Examples
Suppose an XML data structure contains elements with attribute values (in the example below these are street and city), and you want to convert them to an UML class.
...
<address id="myAddress">
<street id="234">Lautengartenstr. 12</street>
<city id="34">Basel</city>
</address>
The class diagram below illustrates how to map the content of the XML element street ("Lautengartenstr. 12") and the value of its attribute id ("234") to the UML association end street:
Figure: Mapping XML Data Structures to UML Classes
The street element from the above XML example is mapped to the association end street. The association end name must be the same as the name of the XML element. The associated class StreetElement is only a container for the street element. The name of the class is not relevant for the mapping. The XML attribute id of the element street is mapped to the class attribute id of the UML class StreetElement. The content of the XML element street is mapped to the class attribute text_value, which has the stereotype <<XMLCharacters>>.
If the XML element contains attributes, which should not be mapped to UML class attributes, an association to a base type can be used. The following example shows this for the element city. The content of the element ("Basel") will be available in city (accessible as attribute of the instantiated class Address2Example1). As the id attribute cannot be mapped, it will be discarded when executing the operation xmlToClass()
.
Figure: Preventing the Mapping of XML Attributes
Below, find the complete class diagram used for mapping the XML document address.xml.
Figure: Example when Using Operation xmlToClass()
If an object of class Address2Example1 were serialized back in a SOAP response, the SOAP message would read:
...
<address2Example1 xmlns:ns1="urn:Services.URLService.URLPort.DataItems" xsi:type="ns1:Address2Example1">
<id xsi:type="xsd:string">34</id>
<street xsi:type="ns1:StreetElement">
<id xsi:type="xsd:string">234</id>
<text_value xsi:type="xsd:string">Lautengartenstr. 12
</text_value>
</street>
<city xsi:type="xsd:string">Basel</city>
</address2Example1>
The same result could be obtained with the following class diagram.
Figure: Class Diagram with XML Stereotypes
With the three XML stereotypes, one has the flexibility to map XML structures in different ways. You can define very compact class diagrams for simple XML structures, but you have also the possibility to map complex XML data structures graphically.
...
icon | false |
---|
...