Book a Demo

Author Topic: Making package XSDSchema breaks behaviour of elements  (Read 3209 times)

benp

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Making package XSDSchema breaks behaviour of elements
« on: July 14, 2016, 08:15:34 pm »
I have create a very simple UML Class diagram. The classes are as follows:

<class> Person:
  Age
  Name

<class> PhysicalCharacteristics
  hair
  height
  weight

I create a directed association between Person and PhysicalCharacteristics on a diagram and label this "Description". At this point I have not applied any XSD stereotypes to the model. The package that this sits in is called "Simple". I generate an XSD from these classes which yields:

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person" type="Person"/>
<xs:complexType name="Person">
<xs:sequence>
<xs:element name="Age" type="xs:int" minOccurs="1" maxOccurs="1"/>
<xs:element name="Name" type="xs:int" minOccurs="1" maxOccurs="1"/>
<xs:element name="Description" type="PhysicalCharacteristics" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="PhysicalCharacteristics" type="PhysicalCharacteristics"/>
<xs:complexType name="PhysicalCharacteristics">
<xs:sequence>
<xs:element name="hair" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="height" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="weight" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

This is all fine, however now I want to ensure that this is in a namespace. The package is called Simple. I select this package and change its stereotype to XSDschema. I set the Target Namespace to be test.simple and the Prefix to be smp. I then regenerate the XSD. Now I have my namespace, but it has completely broken all the elements:

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="test.simple" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:smp="test.simple">
<xs:element name="Person" type="smp:Person"/>
<xs:complexType name="Person">
<xs:sequence>
<xs:element ref="int" minOccurs="1" maxOccurs="1"/>
<xs:element ref="int" minOccurs="1" maxOccurs="1"/>
<xs:element ref="smp:PhysicalCharacteristics" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="PhysicalCharacteristics" type="smp:PhysicalCharacteristics"/>
<xs:complexType name="PhysicalCharacteristics">
<xs:sequence>
<xs:element ref="" minOccurs="1" maxOccurs="1"/>
<xs:element ref="" minOccurs="1" maxOccurs="1"/>
<xs:element ref="" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

I have followed the tutorial here:
http://www.sparxsystems.com/resources/xml_schema_generation.html

Adding the XSDelement stereotype to all the elements cleans things up a bit:

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="test.simple" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:smp="test.simple">
<xs:element name="Person" type="smp:Person"/>
<xs:complexType name="Person">
<xs:sequence>
<xs:element name="Age" type="xs:int" minOccurs="1" maxOccurs="1"/>
<xs:element name="Name" type="xs:int" minOccurs="1" maxOccurs="1"/>
<xs:element ref="smp:PhysicalCharacteristics" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="PhysicalCharacteristics" type="smp:PhysicalCharacteristics"/>
<xs:complexType name="PhysicalCharacteristics">
<xs:sequence>
<xs:element name="hair" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="height" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="weight" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

However I still have lost the desired declaration of Description (see the first XSD output). So my question is how do I get the original XSD style whilst also including a package name from the schema?


benp

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Making package XSDSchema breaks behaviour of elements
« Reply #1 on: July 14, 2016, 11:05:49 pm »
OK, worked it out. I sent to the XSDschema anonymousRole to false.

Clearly the XSDschema attribute overrides the default behaviour when this is not present.