UML associations to XML?

General discussions about code engineering

Moderator: Moderators

UML associations to XML?

Postby jschardt@phlyins.com » Thu Mar 10, 2011 9:51 am

I have created a simple UML class diagram. I used the UML to XML Schema transform to produce an XML schema diagram. I then generated an XSD schema file based on the XML schema diagram.

The resulting schema had one complex type for each class as expected. But the associations between classes were not represented. What happenned to them? How do I get the xsd file to reflect the associations?

I tried adding oneway navigation to each association to no effect. I tried setting the owner of the assocaition to a specific class to no effect. I placed multiplicity and role names on each assocation to no effect. I tried added a stereotype to the relations in the XML schema diagram but could not.

What am I missing? Thanks in advance for your help.

cheers,
Jim
jschardt@phlyins.com
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Thu Mar 10, 2011 9:34 am

Re: UML associations to XML?

Postby TomasJkn » Fri Mar 11, 2011 9:58 am

Hello Jim,

If I remember correctly, UML->XML schema transformation only knows how to transform composite associations.
Freeform (non-composite) UML associations do not have a nice corresponding concept in XML schemas (probably the closest analogue would be some complex layout with keys/key references).
So instead of:
I tried adding oneway navigation to each association to no effect.

try to make your associations composite (i.e. with black diamond at one end)
Tomas Juknevicius
Senior Systems Analyst
No Magic Europe
TomasJkn
Customer Support
Customer Support
 
Posts: 63
Posts Rating:6
Joined: Mon May 10, 2010 9:24 am

Re: UML associations to XML?

Postby jschardt@phlyins.com » Fri Mar 11, 2011 4:21 pm

I tried your suggestion. Each association was turned into a composite. The UML to XML transform worked fine. But the generation of the xsd had the same result -- an xsd file with complex types one for each class. The composites were not included.

Any suggestions? Can you show me a simple working example?

Thanks,
Jim
jschardt@phlyins.com
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Thu Mar 10, 2011 9:34 am

Re: UML associations to XML?

Postby TomasJkn » Mon Mar 14, 2011 9:20 am

Hello Jim,

Here is a simple example with 2 classes - a and b.
Those were transformed into XML schema model
and the schema file was subsequently generated from that

I have only made some renames in the schema model after the transformation:
uml.xsd (class)->my.xsd
uml (package)->http://my.com/MyNamespace
UML (diagram)->XSD

as can be seen, the resulting my.xsd contains two complex types (one for each class); complex type a has a composite element of type b:
Code: Select all
<xs:complexType name="a">
   <xs:sequence>
      <xs:element maxOccurs="unbounded" minOccurs="0" name="member" type="b"/>
   </xs:sequence>
</xs:complexType>


I hope it helps.
You do not have the required permissions to view the files attached to this post.
Tomas Juknevicius
Senior Systems Analyst
No Magic Europe
TomasJkn
Customer Support
Customer Support
 
Posts: 63
Posts Rating:6
Joined: Mon May 10, 2010 9:24 am

Re: UML associations to XML?

Postby jschardt@phlyins.com » Thu Mar 17, 2011 2:53 pm

Ok, I now I am able to make UML assoications work. It turns out that when you want assocations to map properly to an XSD diagram and then on to an xsd file you need to have a role name on the association and you need to select your transformation items very carefully.

Now I am own to another issue -- seperating UML classes across packages and thus seperating complex types across name spaces.

I have a BaseType namespace that defines Address. The BaseType.xsd file is generated properly - no problem. Then I have a PersonDriver namespace. This namespace/package(with xsd stereotyped classes) contains Person and Driver. Driver has an association to Address with the role of home. The classes in MagicDraw are stereotyped properly. But when I generate the xsd file PersonDriver.xsd the xsd validator cannot resolve the Address type.

When I generate the PersonDriver.xsd file MagicDraw throws up the following message:
Syntax checking was made on temporary file file:///C:/TestUML2xsdXSDs/PersonDriver.xsd.tmp
Model contains the following errors:
Error: 9:84: src-resolve.4.2: Error resolving component 'Address'. It was detected that 'Address' is in namespace 'BaseTypes.xsd', but components from this namespace are not referenceable from schema document 'file:///C:/TestUML2xsdXSDs/PersonDriver.xsd.tmp'. If this is the incorrect namespace, perhaps the prefix of 'Address' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///C:/TestUML2xsdXSDs/PersonDriver.xsd.tmp'.


How would you get this to work properly?

Cheers,
Jim
You do not have the required permissions to view the files attached to this post.
jschardt@phlyins.com
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Thu Mar 10, 2011 9:34 am

Re: UML associations to XML?

Postby jschardt@phlyins.com » Mon Mar 21, 2011 2:07 pm

Problem solved.

When using the multiple name spaces you need to add a couple of dependencies. From the XSDschema class A create an XSDImport from the schema class A to the package P that encloses the name space with element you want to use. Secondly, create an xmlns dependency between the schema class A and the package P.
jschardt@phlyins.com
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Thu Mar 10, 2011 9:34 am

Re: UML associations to XML?

Postby saulius_p » Tue Mar 22, 2011 5:42 am

Hello,

Thank you for providing the status. We are glad to hear that solution was found.

If you have any other questions, please feel free to post them.
Best regards,
Saulius Pavalkis
User avatar
saulius_p
No Magic
No Magic
 
Posts: 259
Posts Rating:8
Joined: Fri Dec 04, 2009 5:37 am
Full name: Saulius Pavalkis


Return to Code engineering

Who is online

Users browsing this forum: No registered users and 0 guests

cron