Author Topic: XML Schema Generation  (Read 3089 times)

ngong

  • EA User
  • **
  • Posts: 273
  • Karma: +1/-2
    • View Profile
XML Schema Generation
« on: February 03, 2023, 02:13:17 am »
Seems like an error - or do I do something wrong?

I am trying to generate an XML Schema with an recursive element.
You may download a qea file that demonstrates my problem.

It generates
Quote
   <xs:complexType name="Check">
      <xs:sequence>
         <xs:element ref="Check" minOccurs="1" maxOccurs="1"/>
      </xs:sequence>
   </xs:complexType>
where it should generate
Quote
   <xs:complexType name="Check">
      <xs:sequence>
         <xs:element ref="Check" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
   </xs:complexType>

Is that a flaw of the XSD generator in EA or my fault anyhow?
Rolf

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13251
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XML Schema Generation
« Reply #1 on: February 03, 2023, 02:20:04 am »
In the properties of you element, you can set the multiplicity.
That will be translated to minOccurs/maxOccurs
(so either on the association, or on on the attribute, depending on your modelling style)

Geert

ngong

  • EA User
  • **
  • Posts: 273
  • Karma: +1/-2
    • View Profile
Re: XML Schema Generation
« Reply #2 on: February 11, 2023, 03:50:48 am »
As you may see, Geert, on the Check diagram the association contains zero-to-many (0..*).
This works fine in generation between two different classes but not in recursion.

To the model I have added a Detail table, Check table is the master. Both associations are zero-to-many, the recursive one and the one from Check to Detail.

The result is daunting. The zero-to-many in the recursion association is ignored. Instead a one-to-one association is generated:

Quote
<?xml  version='1.0' encoding='utf-8' ?>
<xs:schema targetNamespace="eu.ngong.Check" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="eu.ngong.Check" xmlns:ch="eu.ngong.Check">
   <xs:element name="Check" type="ch:Check"/>
   <xs:complexType name="Check">
      <xs:sequence>
         <xs:element ref="Check" minOccurs="1" maxOccurs="1"/>
         <xs:element ref="Detail" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="Detail">
      <xs:sequence/>
   </xs:complexType>
</xs:schema>

I could not find an Multiplicity property other than at the Source or Target of an association. Do you mean a different one?
« Last Edit: February 11, 2023, 04:02:49 am by ngong »
Rolf

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: XML Schema Generation
« Reply #3 on: February 11, 2023, 08:08:11 am »
More a side note: there is no 1:1 mapping between UML and XSD. Once I created a dedicated im-/export for a customer via scripting. It was a bit of work but it was adaptable to the customer's needs. So probably worth the money spent.

q.

ngong

  • EA User
  • **
  • Posts: 273
  • Karma: +1/-2
    • View Profile
Re: XML Schema Generation
« Reply #4 on: February 11, 2023, 04:49:29 pm »
@qwerty: May be I was not clear enough: I do not ask about a relation between UML and XSD. In my example model, the class Check has an association to itself. And its a zero-to-many relation. The XSD generator of EA translates my model to minOccurs="1" maxOccurs="1", while I expected minOccurs="0" maxOccurs="unbounded".

That is, the XSD generator of EA translates my model to a relation between the Check parent and its related Check children as if I had a one-to-one relation in my model. But that is not true. In the model it shows a zero-to-many relation between Check and itself. In the same way as there is a zero-to-many relation between the classes Check and Detail. The XSD generator translates that relation as I have expected. Why not for the Check:Check relation in the same way?

The question is: Is my understanding or model wrong or is the XSD generator of EA in error?

the image of the class diagram
I would love to show the model image here, but was not able to find a description, how the [img ][/img] markup works.
« Last Edit: February 11, 2023, 05:06:59 pm by ngong »
Rolf

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13251
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XML Schema Generation
« Reply #5 on: February 11, 2023, 06:36:14 pm »
the image of the class diagram
I would love to show the model image here, but was not able to find a description, how the [img ][/img] markup works.
You you post the image on a public image hosting site such as imgur.com?
Your URL doesn't work for me.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: XML Schema Generation
« Reply #6 on: February 11, 2023, 10:35:13 pm »
Link works for me. @ngong: EA is doing some conversion following it's own rules. These rules are burned in EA's code and you must accept them. I explained just, why.

q.

ngong

  • EA User
  • **
  • Posts: 273
  • Karma: +1/-2
    • View Profile
Re: XML Schema Generation
« Reply #7 on: February 13, 2023, 03:15:56 am »
@Geert: here is the link to Imgur.com. But why this forum offers a button Insert image that puts the markup [img ][/img ] in the text? How can I use  [img ][/img ] to show an image directly?
@qwerty: Every other generation seems to be quite logic, except this one. Looks to me as a failure in generation. Maybe I should file an issue at Sparx.
« Last Edit: February 13, 2023, 04:27:46 am by ngong »
Rolf

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: XML Schema Generation
« Reply #8 on: February 13, 2023, 05:05:24 am »
The img is a placebo. So to say. You can include a image url within like
Code: [Select]
[img]https://www.sparxsystems.com/forums/smf/Themes/default/images/smflogo.png[/img] which renders as
But only if it does not get up hickups from those annoying cookie-alerts.
The forum SW is obviously not rocket science.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13251
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XML Schema Generation
« Reply #9 on: February 13, 2023, 04:19:33 pm »
You definitely don't need compositions, in xsd modelling, and I would even avoid associations.
You can model the same thing using attributes.

The benefit of using attributes is that you don't have to worry about the direction of the association, and more importantly, you don't have to manually set the sequence order of the assocations.

Geert

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: XML Schema Generation
« Reply #10 on: February 15, 2023, 08:42:53 pm »
You definitely don't need compositions, in xsd modelling, and I would even avoid associations.
You can model the same thing using attributes.

The benefit of using attributes is that you don't have to worry about the direction of the association, and more importantly, you don't have to manually set the sequence order of the assocations.

Geert
The compositions could be behind the problem, I would suggest changing them to associations, generating the XSD and testing the results. Having said this, if Sparx EA is behaving as described because of the compositions, we have reached a new level of weird functionality. I have to agree the XSD does not truly represent the model.

With regards to associations vs attributes, from memory Sparx EA used to reverse engineer them in a very different way, and, I would expect Sparx forward engineering them - i.e., generating the XSD - also in a different way.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13251
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XML Schema Generation
« Reply #11 on: February 15, 2023, 08:47:05 pm »
With regards to associations vs attributes, from memory Sparx EA used to reverse engineer them in a very different way, and, I would expect Sparx forward engineering them - i.e., generating the XSD - also in a different way.

You can do almost anything in XSD modelling using only attributes. That makes things a lot easier (mainly because of the sequence ordering)

IIRC only choice objects require the use of associations, but I'm not sure anymore.

Geert