Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XSD Question: maps in XSD
XSD Question: maps in XSD [message #402424] Thu, 13 July 2006 16:18 Go to next message
Eclipse UserFriend
Originally posted by: philipp.kutter.org

Hi, All.
I have an XSD Schema with instances of Type A.

Now I would like to add a map, from A to A, where the key is a
refrerence, and the value is a containment.

I know how to do this in Java and in ECore, but not in XSD.

When I tried to load from the generated XSD fragment:

<xsd:complexType name="XMLToXMLMapEntry">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="key" type="mtgDecoration:MXmlElement"/>
<xsd:element name="value" type="mtgDecoration:MXmlElement"/>
<xsd:element ref="xmi:Extension"/>
</xsd:choice>
<xsd:attribute ref="xmi:id"/>
<xsd:attributeGroup ref="xmi:ObjectAttribs"/>
<xsd:attribute name="key" type="xsd:string"/>
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>

It did not work, and it looks overly complex.

Is there any built in support in EMF/XSD for this?

Best Regards, Philipp
Re: XSD Question: maps in XSD [message #402428 is a reply to message #402424] Thu, 13 July 2006 16:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060307060603090902040505
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Philipp,

Here's what Ecore.xsd looks like:

<xsd:complexType name="EAnnotation">
<xsd:complexContent>
<xsd:extension base="ecore:EModelElement">
<xsd:sequence>
*<xsd:element maxOccurs="unbounded" minOccurs="0"
name="details" type="ecore:EStringToStringMapEntry"/>*
<xsd:element maxOccurs="unbounded" minOccurs="0" name="contents"/>
</xsd:sequence>
<xsd:attribute name="source" type="ecore:EString"/>
<xsd:attribute ecore:opposite="eAnnotations"
ecore:reference="ecore:EModelElement" ecore:transient="true"
name="eModelElement" type="xsd:IDREF"/>
<xsd:attribute ecore:reference="xsd:anyType" name="references">
<xsd:simpleType>
<xsd:list itemType="xsd:anyURI"/>
</xsd:simpleType>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

* <xsd:complexType ecore:instanceClass="java.util.Map$Entry"
name="EStringToStringMapEntry">
<xsd:attribute name="key" type="ecore:EString"/>
<xsd:attribute name="value" type="ecore:EString"/>
</xsd:complexType> *

If you know how to do it in Ecore, you can try exporting the .ecore to
an XML Schema and see what it produces. I've tried to make the Ecore ->
XML Schema -> Ecore be as roundtrippable as possible...


Philipp W. Kutter wrote:
> Hi, All.
> I have an XSD Schema with instances of Type A.
>
> Now I would like to add a map, from A to A, where the key is a
> refrerence, and the value is a containment.
>
> I know how to do this in Java and in ECore, but not in XSD.
>
> When I tried to load from the generated XSD fragment:
>
> <xsd:complexType name="XMLToXMLMapEntry">
> <xsd:choice maxOccurs="unbounded" minOccurs="0">
> <xsd:element name="key" type="mtgDecoration:MXmlElement"/>
> <xsd:element name="value" type="mtgDecoration:MXmlElement"/>
> <xsd:element ref="xmi:Extension"/>
> </xsd:choice>
> <xsd:attribute ref="xmi:id"/>
> <xsd:attributeGroup ref="xmi:ObjectAttribs"/>
> <xsd:attribute name="key" type="xsd:string"/>
> <xsd:attribute name="value" type="xsd:string"/>
> </xsd:complexType>
>
> It did not work, and it looks overly complex.
>
> Is there any built in support in EMF/XSD for this?
>
> Best Regards, Philipp
>


--------------060307060603090902040505
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Philipp,<br>
<br>
Here's what Ecore.xsd looks like:<br>
<small><br>
&nbsp; &lt;xsd:complexType name="EAnnotation"&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:complexContent&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:extension base="ecore:EModelElement"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:sequence&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>&lt;xsd:element maxOccurs="unbounded" minOccurs="0"
name="details" type="ecore:EStringToStringMapEntry"/&gt;</b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:element maxOccurs="unbounded" minOccurs="0"
name="contents"/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xsd:sequence&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:attribute name="source" type="ecore:EString"/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:attribute ecore:opposite="eAnnotations"
ecore:reference="ecore:EModelElement" ecore:transient="true"
name="eModelElement" type="xsd:IDREF"/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:attribute ecore:reference="xsd:anyType"
name="references"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:simpleType&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:list itemType="xsd:anyURI"/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/xsd:simpleType&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xsd:attribute&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:extension&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/xsd:complexContent&gt;<br>
&nbsp; &lt;/xsd:complexType&gt;</small><br>
<br>
<b><small>&nbsp; &lt;xsd:complexType
ecore:instanceClass="java.util.Map$Entry"
name="EStringToStringMapEntry"&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="key" type="ecore:EString"/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="value" type="ecore:EString"/&gt;<br>
&nbsp; &lt;/xsd:complexType&gt;&nbsp;</small></b><br >
<div><br>
</div>
If you know how to do it in Ecore, you can try exporting the .ecore to
an XML Schema and see what it produces.&nbsp; I've tried to make the Ecore
-&gt; XML Schema -&gt; Ecore be as roundtrippable as possible...<br>
<br>
<br>
Philipp W. Kutter wrote:
<blockquote cite="mide95roa$4ra$1@utils.eclipse.org" type="cite">
<pre wrap="">Hi, All.
I have an XSD Schema with instances of Type A.

Now I would like to add a map, from A to A, where the key is a
refrerence, and the value is a containment.

I know how to do this in Java and in ECore, but not in XSD.

When I tried to load from the generated XSD fragment:

&lt;xsd:complexType name="XMLToXMLMapEntry"&gt;
&lt;xsd:choice maxOccurs="unbounded" minOccurs="0"&gt;
&lt;xsd:element name="key" type="mtgDecoration:MXmlElement"/&gt;
&lt;xsd:element name="value" type="mtgDecoration:MXmlElement"/&gt;
&lt;xsd:element ref="xmi:Extension"/&gt;
&lt;/xsd:choice&gt;
&lt;xsd:attribute ref="xmi:id"/&gt;
&lt;xsd:attributeGroup ref="xmi:ObjectAttribs"/&gt;
&lt;xsd:attribute name="key" type="xsd:string"/&gt;
&lt;xsd:attribute name="value" type="xsd:string"/&gt;
&lt;/xsd:complexType&gt;

It did not work, and it looks overly complex.

Is there any built in support in EMF/XSD for this?

Best Regards, Philipp
</pre>
</blockquote>
<br>
</body>
</html>

--------------060307060603090902040505--


Ed Merks
Professional Support: https://www.macromodeling.com/
perfect, it works in all variants! [message #402451 is a reply to message #402428] Fri, 14 July 2006 13:08 Go to previous messageGo to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
Thanks a lot.
I got it to work, both string to string, object ref to object ref,
and object ref to contained object. See the minimal XSD below.

Best, Philipp

PS: a pitty that there is no place one can look for
"map XSD EMF" and get the info.


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
targetNamespace="http://www.montages.com/mtg/MTGDECORATION"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:mtgDecoration="http://www.montages.com/mtg/MTGDECORATION"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:complexType name="MAny">
<xsd:sequence>
<xsd:element name="child" type="mtgDecoration:MAny"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="details"
type="mtgDecoration:MStringToStringMapEntry"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="any2any"
type="mtgDecoration:MAnyToAnyMapEntry"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="any2anyContained" type="mtgDecoration:MAnyToAnyContainedMapEntry"/>
</xsd:sequence>
<xsd:attribute name="ref" ecore:reference="mtgDecoration:MAny"
type="xsd:anyURI"/>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>



<xsd:complexType ecore:instanceClass="java.util.Map$Entry"
name="MStringToStringMapEntry">
<xsd:attribute name="key" type="xsd:string"/>
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>

<xsd:complexType ecore:instanceClass="java.util.Map$Entry"
name="MAnyToAnyMapEntry">
<xsd:attribute name="key" ecore:reference="mtgDecoration:MAny"
type="xsd:anyURI"/>
<xsd:attribute name="value" ecore:reference="mtgDecoration:MAny"
type="xsd:anyURI"/>
</xsd:complexType>

<xsd:complexType ecore:instanceClass="java.util.Map$Entry"
name="MAnyToAnyContainedMapEntry">
<xsd:sequence>
<xsd:element name="value" type="mtgDecoration:MAny"/>
</xsd:sequence>
<xsd:attribute name="key" ecore:reference="mtgDecoration:MAny"
type="xsd:anyURI"/>
</xsd:complexType>

</xsd:schema>
Re: perfect, it works in all variants! [message #402452 is a reply to message #402451] Fri, 14 July 2006 13:56 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Philipp,

There's this
http://www.eclipse.org/emf/docs/overviews/XMLSchemaToEcoreMa pping.pdf
but it's out of date and it doesn't specifically cover maps, although
there aren't really any map specific annotations, you just use general
purpose annotations to achieve a map result...


Philipp W. Kutter wrote:
> Thanks a lot.
> I got it to work, both string to string, object ref to object ref,
> and object ref to contained object. See the minimal XSD below.
>
> Best, Philipp
>
> PS: a pitty that there is no place one can look for
> "map XSD EMF" and get the info.
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
> targetNamespace="http://www.montages.com/mtg/MTGDECORATION"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:mtgDecoration="http://www.montages.com/mtg/MTGDECORATION"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
> <xsd:complexType name="MAny">
> <xsd:sequence>
> <xsd:element name="child" type="mtgDecoration:MAny"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="details" type="mtgDecoration:MStringToStringMapEntry"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="any2any" type="mtgDecoration:MAnyToAnyMapEntry"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="any2anyContained" type="mtgDecoration:MAnyToAnyContainedMapEntry"/>
> </xsd:sequence>
> <xsd:attribute name="ref"
> ecore:reference="mtgDecoration:MAny" type="xsd:anyURI"/>
> <xsd:attribute name="id" type="xsd:string"/>
> </xsd:complexType>
>
>
>
> <xsd:complexType ecore:instanceClass="java.util.Map$Entry"
> name="MStringToStringMapEntry">
> <xsd:attribute name="key" type="xsd:string"/>
> <xsd:attribute name="value" type="xsd:string"/>
> </xsd:complexType>
>
> <xsd:complexType ecore:instanceClass="java.util.Map$Entry"
> name="MAnyToAnyMapEntry">
> <xsd:attribute name="key" ecore:reference="mtgDecoration:MAny"
> type="xsd:anyURI"/>
> <xsd:attribute name="value" ecore:reference="mtgDecoration:MAny"
> type="xsd:anyURI"/>
> </xsd:complexType>
>
> <xsd:complexType ecore:instanceClass="java.util.Map$Entry"
> name="MAnyToAnyContainedMapEntry">
> <xsd:sequence>
> <xsd:element name="value" type="mtgDecoration:MAny"/>
> </xsd:sequence>
> <xsd:attribute name="key" ecore:reference="mtgDecoration:MAny"
> type="xsd:anyURI"/>
> </xsd:complexType>
>
> </xsd:schema>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Ecore2Ecore and Ecore2XML
Next Topic:Turn off Lazy Loading?
Goto Forum:
  


Current Time: Thu Apr 25 08:51:30 GMT 2024

Powered by FUDForum. Page generated in 0.03496 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top