Hello,
I’m working on a proof of concept to generate XML schemas from idiomatic UML class diagrams (PIM). The current generator supports the XSD concept of derivation by extension, but not restriction. Extension is archived by the extending class E to generalize the base class B. The extending class can specify additional attributes that will transform into XSD attributes or elements, as directed by stereotypes/tags placed upon it.
Derivation by restriction is more difficult. It seems that using a generalization between the restricting class R to the base class B would imply inheritance of the base class’s attributes, which is undesirable. My best guess is to place a specific associative property from R to B (say “derived by restriction from”), and then allow attributes of B to be defined in R to inherit the attributes and cardinality. If a minimum cardinality restriction is required, the attribute must {subsets baseAttribute}. If a maximum cardinality restriction is required, the attribute must {redefines baseAttribute}.
I'm looking for someone who knows both UML and XSD to provide feedback on this approach or suggest another. An example follows:
UML Model
B -------------------------- -attributeA: string [0..1] -attributeB: string [1..5] -attributeC: string [2..3]
R -------------------------- -attributeA: string [0..1] -attributeB: string [2..5] {subsets attributeB} -attributeC: string [2] {redefined attributeC}
Association:derived by restriction from[::R -> ::B]
Should transform into
```xsd <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns="_18_5_3_43701b0_1521039686632_995340_5448" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="_18_5_3_43701b0_1521039686632_995340_5448" elementFormDefault="qualified" version="1.0"> <xsd:complexType name="B"> <xsd:sequence> <xsd:element name="attributeA" minOccurs="0"/> <xsd:element name="attributeB" type="xsd:string" maxOccurs="5"/> <xsd:element name="attributeC" type="xsd:string" minOccurs="2" maxOccurs="3"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="R"> <xsd:complexContent> <xsd:restriction base="B"> <xsd:sequence> <xsd:element name="attributeA" minOccurs="0"/> <xsd:element name="attributeB" type="xsd:string" minOccurs="2" maxOccurs="5"/> <xsd:element name="attributeC" type="xsd:string" minOccurs="2" maxOccurs="2"/> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType> </xsd:schema> ```
(yes, the attributes in the UML transformed into elements on the XSD side)
Thanks,
John Dziurlaj |