Packages / Schema part II

Hi Jick (or whoever the new Jick is :smiley: )

I’m back working as a modeler for another organisation and am in the process of creating all the models and data definitions.

I’m creating all the models as class diagrams with XML as the default programming language.

The question I have at the moment is around the schema generation - I have changed the XsdPackage.vm file to allow me to use UTF-8 as a hard coded change but there are a couple of other things that I would like to do from the tagged values within the UML package property.

Firstly I would like to add in the elementFormDefault, attributeFormDefault and version into the xs:schema definition. My assumption would be that it would work the same way as xs:restriction@base and others are used to provide facet information from within a class.

The second is the way that namespaces are generated in the XSD file - Specifically the ability to name the namespace rather than have ns0, ns1, ns2 etc assigned to them.

I can provide examples of what I mean if this helps…

I am using the v7 Professional version of VP on OSX.

Many thanks in advance

Hello Toby,

Thank you for your message. For your first question, do you mean you want to define tagged values which will be reflected in generated XML? And for the second question, would you mind send me some samples about what you exactly want? Look forward to hear your reply.

Best regards,
Rain

Hi Rain

There are a couple of issues really.

  1. Assuming that UML package = schema there is no ability to provide information as to the namespace. VP does pick up that the package has a namespace but then it will autogenerate the short code (xmlns:n0=“http://my.namespace”) rather than give you the chance to specify it. For example, in the attached project there is a package called core, which has come from a central government XSD. Within the model it is correctly referenced (core.RestrictedStringType) but when you generate it drops to ns0. If I was to generate all the packages then it would be ok, but the idea is that I can import it once, use it and then always refer to the original copy of the file.

  2. If you create a package name with “.” in it the generator replaces it with “/” - with the above file the core namespace is http://www.govtalk.gov.uk/core which then gets converted on output to http://untilted/www/govtalk/gov/uk

  3. In the generator advanced options it does not matter what encoding you select you always end up with ISO-8859-1

More than happy to try to give you more background and info; its friday afternoon so my desire to stay in the office is low :smiley:

Have a great weekend

Toby
CommonSimpleTypes-v1-3.xsd
tmp.vpp

Hello Toby,

For Q1, so you mean you would prefer generate the element as follow?


<xs:element name="attribute" type="core:RestrictedStringType" minOccurs="0" maxOccurs="1">
</xs:element>

For Q2 and Q3, we consider they are bug and will let you know once it was fixed.

Best regards,
Rain

Hi Rain - that would be perfect!

Let me know when you have something for me to test - remember that I am on the OSX version of VP.

I’m glad to see that the support is as good as it was! Many thanks for getting back to me so quickly

Hello Toby,

I would like to let you know we released a patch build which fixed the encoding and the namespace substitution (ns0, ns1…) problem (Q1 & Q3). You can download the patch build at the following link

http://files2.visual-paradigm.com/200906/Patch/20090530m/VP_Suite_MacOSX_4_0_20090530m.dmg

For Q2, you will see there is an extra field available in the XML Schema Generator dialog which allow you specify the namespace. You can specify www.govtalk.gov.uk so that it will namespace without replace “.” with “/”. But this only work for your defined workspace. For the www.toby, do you also prefer they generate without replace “.” with “/”?

Best regards,
Rain

Hi Rain - the www.toby was just an example so please dont integrate it into the product (although it might keep me in work!).

I’m just downloading the patch build and will report back in a day or so…

Thank you very much for a speedy answer :wink:

Hello Toby,

There is a minor issue in the “m” build you downloaded previously. Please download the latest one at

http://files2.visual-paradigm.com/200906/Patch/20090531a/VP_Suite_MacOSX_4_0_20090531a.dmg

Best regards,
Rain

Thanks Rain - installed and will try to check it today…

You are welcome.

Hi Rain - its me back again :wink:

All is great but I have run into an issue with xs:choice. There is no coding in the xsdClass.vm file to cope with it. I can see the following code copes with the xs:sequence or xs:all:

#if( $class.xsdElementAttributeCount() > 0 )
#if( $class.isSequence() )
$indenter.getIndentation()xs:sequence
#else
$indenter.getIndentation()xs:all
#end
$indenter.push($indentation)##
#foreach( $attribute in $class.xsdElementAttributeIterator() )
#parse("$template-dir/XsdElementAttribute.vm")
#end
$indenter.pop()##
#if( $class.isSequence() )
$indenter.getIndentation()</xs:sequence>
#else
$indenter.getIndentation()</xs:all>
#end
#end

I guess that there is no $class.isChoice() which is why it fails…

Any chance that you can correct this? More than happy to help test and get a result! I’ve just convinced the company that I am working for to standardize on VP so add a couple of more clients to your install base :wink:

Many thanks…

This is a bit off topic, but because I am going through similar issues, and I think it would be great to have a tutorial on creating XML Schema’s using VPUML. I generate simple schemas, but don’t really know how to have it automatically reference other schemas, how to go about importing them for reference, and how to set the correct relationships in VP UML to get the desired structure. There are some code generation topics about some of the programming languages in the docs, but not for XML/XSD. I think a developer blog with tips would be great too. Thanks.

EDIT 1:
I found specs here: http://xmlmodeling.com/documentation/specs/
which apply to their tool.

UML Profile for XSD
A UML profile of sterotypes that extend models with XML Schema properties that cannot be represented in UML alone.
UML Profile for XSD Generation
A UML profile of sterotypes that extend models with XML Schema style preferences.

Is there such documentation for VP so that we understand exactly what will happen with XML? Do these documents apply?

Hi Toby,

I’ve forwarded your issue to our engineers to follow-up. I’ll notify you once there is any news on this issue.

Best regards,
Lilian Wong

Hi Captain,

Thanks for your post. Could you please tell me what do you mean by “reference other schemas”, “import them” amd “set the correct relationship”? Thanks!

Best regards,
Lilian Wong

Hi Captain,

I think that I understand your question - you have some external schema which define complex and simple types that you want to use within your own project.

The approach that I have taken is to create a package with the same namespace as the external schema (ns1, ns2 etc). For the schema file that I attached above it needs to be a namespace called core - the xsd would look like:


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:core="http://www.govtalk.gov.uk/core">
    <xs:import schemaLocation="CommonSimpleTypes-v1-3.xsd" id="Core"
        namespace="http://www.govtalk.gov.uk/core"/>
    <xs:element name="tja" type="core:RestrictedStringType" default=""/>
</xs:schema>

I then create the classes that I need inside of that package and use the package name as the namespace prefix. I then create the schema that I need to model - I have attached a jpg as an example.

When my model is complete, I generate using instant generator and ONLY generate my schema - I do not generate the external schema. In the above picture, instant generator would give:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema 
	targetNamespace="http://untitled" 
	xmlns="http://untitled" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="tjaPerson">
		<xs:complexType>
			<xs:sequence>		
				<xs:element name="attribute" type="core:MaritalStatusType" minOccurs="0" maxOccurs="1">
				</xs:element>
				<xs:element name="attribute2" type="core:RestrictedStringType" minOccurs="0" maxOccurs="1">
				</xs:element>
				<xs:element name="attribute3" type="core:YesNoType" minOccurs="0" maxOccurs="1">
				</xs:element>
			</xs:sequence>	
		</xs:complexType>
	</xs:element>
</xs:schema>

I then manually edit the xs:schema element to include the external NS references and the xs:import statements to allow me to reuse the external references…

Does this make any sense? I’ve been using VP to generate models and schema for some time so I have some background in it - it might not be the most elegant way of achieving the result but it works and it keeps the model clean. I have worked with both Jick and Lilian to correct some of the problems in the VP code but it is very unlikely that it will be possible to completely autogenerate schema from a model - UML is just not geared to do that sort of thing!

Feel free to drop me a reply - I would like this thread to become a best practice area; if I had more time then I would happily write a guide :wink:
tmp.jpg

Toby, thank you for taking the time to write that post. It did clarify things a bit for me.

Lilian, Toby was correct when he mentioned using an external schema that defines some types that I want to use. I have the schema, and I was looking for a way to import it into VPUML so that the classes and relationships are represented, and then be able to reference those in my schema. Toby’s technique to represent the necessary external schema types in a package works. Though, in more complex examples, this may be tedious.

After an initial search online, it seems that there are techniques for using UML to represent XML schemas, but maybe no standard set of extensions to UML that allow for this. Some ideas seemingly go in to detail about using stereotypes a certain way to get the necessary functionality. Even for simple tasks, I can’t stand working with XML schemas. There is too much angle bracket clutter and my mind doesn’t have an easy time forming a picture of the structure of the relationships.

I’ll make a second post shortly with a current task and we can run through a simple example of creating a schema.

For me, most of the external schema are UK Government schema or other organizations so once created then the list of reusable components are fairly static (the joy of consistent data standards). For a more change-driven enviroment I can see that it would be a headache! The advantage of the technique is if VP ever fully supports XSD then your project is not trashed!.

let me know what you are trying to achieve and I’ll see what I can assist with.

Hi Toby,

I would like to let you know that we fixed the problem of no $class.isChoice(), and the patch I sent in forum http://forums.visual-paradigm.com/posts/list/49352.html contains this fix as well.

Best regards,
Lilian Wong

[quote=TobyAnscombe]Hi Rain

There are a couple of issues really.

  1. Assuming that UML package = schema there is no ability to provide information as to the namespace. VP does pick up that the package has a namespace but then it will autogenerate the short code (xmlns:n0=“http://my.namespace”) rather than give you the chance to specify it. For example, in the attached project there is a package called core, which has come from a central government XSD. Within the model it is correctly referenced (core.RestrictedStringType) but when you generate it drops to ns0. If I was to generate all the packages then it would be ok, but the idea is that I can import it once, use it and then always refer to the original copy of the file.

  2. If you create a package name with “.” in it the generator replaces it with “/” - with the above file the core namespace is http://www.govtalk.gov.uk/core which then gets converted on output to http://untilted/www/govtalk/gov/uk

  3. In the generator advanced options it does not matter what encoding you select you always end up with ISO-8859-1

More than happy to try to give you more background and info; its friday afternoon so my desire to stay in the office is low :smiley:

Have a great weekend

Toby[/quote]
Such a very amazing link!