How to specify string maxLength in UML for XSD

Discussions about database modeling product Cameo Data Modeler functionalities

Moderator: Moderators

How to specify string maxLength in UML for XSD

Postby jaschikp » Tue Feb 21, 2017 7:58 am

I am modelling application data in MagicDraw UML Class diagram.
Finally I need to get XSD from my data model.
I managed to use UML to XSD model transformation, create XSD code engineering set and generate XSD (made use of Cameo Data Modeler plugin).
That was good for classes, enumerations, attributes and primitive types from UML Standard profile.

But I have difficulties with modeling simple XSD restrictions, like element of type string with maxLength, or with pattern:
Code: Select all
      <xs:element name="firstName">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="5"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

Code: Select all
      <xs:element name="surName">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>


How to model in UML such class attribute properties (maxLength, pattern) to be able to get them right in finally generated XSD?
jaschikp
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Tue Feb 21, 2017 7:36 am

Re: How to specify string maxLength in UML for XSD

Postby gedkvi » Wed Feb 22, 2017 5:51 am

Hello,

You can create XSD restrictions by doing this:
1) Click on Class by Pattern
2) Click on a diagram
3) Select Simple XSDRestriction
4) Fill out the properties that should be set. e.g. the base( string in your case ), and maxLength, pattern.
restriction.png


This is a sample it could look like in a diagram:
restriction2.png


If you generate and XSD file, this will be the outcome:
Code: Select all
<?xml version='1.0' encoding='UTF-8'?>
<xs:schema targetNamespace="http://test" xmlns="http://test" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:simpleType name="myType">
      <xs:restriction base="xs:string">
         <xs:length value="8"/>
      </xs:restriction>
   </xs:simpleType>
   <xs:simpleType name="myType2">
      <xs:restriction base="xs:string">
         <xs:minLength value="1"/>
         <xs:maxLength value="10"/>
         <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
      </xs:restriction>
   </xs:simpleType>
</xs:schema>


I have also attached a sample project for you to try out.

Sincerely,
No Magic Customer Support
You do not have the required permissions to view the files attached to this post.
gedkvi
Customer Support
Customer Support
 
Posts: 55
Posts Rating:7
Joined: Wed Sep 16, 2015 11:25 am

Re: How to specify string maxLength in UML for XSD

Postby jaschikp » Wed Feb 22, 2017 2:56 pm

Hi,
Thank you for your answer.
However, described by you approach is not exactly what we need.

You suggested to model XSDrestriction directly in XML Schema Diagram, and in your sample mdzip such "XML schema model" is the initial one.
You are not using "UML to XML Schema" transformation.

What we need is:
1) To model application data in so called "abstract UML model" (not yet applying stereotypes from "XML Schema Profile").
2) From "1)" abstract UML model get XSD.

1 abstract UML model.PNG


We figured out, that for that purpose Cameo Data Modeler should be used with additional ritual dances:
a) Using "UML to XML Schema" transformation from "Model Transformations", from "1)" abstract UML model generate equivalent "XML schema model".
b) Using "XML Schema" in "Code engineering sets", from "a)" XML schema model generate final "2)" XSD.
I.e., we are modeling only on "1)", and then after each model update cycle to get to required updated "2)", we are performing same ritual: "1)" -> "a)" -> "b)" -> "2)".

a+b XML schema model.PNG


So, we don`t directly model in "a)" XML schema model.
Even if we do so, with following "1)" update cycle, we would lose those changes performing routine "1)" -> "a)" "UML to XML Schema" transformation.

We would like to know how it is advised to model mentioned in my initial post XSD restriction on "1)" abstract UML model so, that it would propagate through "1)" -> "a)" -> "b)" -> "2)" ritual, and finally would appear in resulting "2)" XSD?

Attaching sample mdzip:
UmlToXsd2.mdzip
You do not have the required permissions to view the files attached to this post.
jaschikp
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Tue Feb 21, 2017 7:36 am


Return to Cameo Data Modeler

Who is online

Users browsing this forum: No registered users and 0 guests