XML serialization [message #1764385] |
Mon, 29 May 2017 10:06 |
Peter Mising name Messages: 95 Registered: July 2009 |
Member |
|
|
Hello, I have a little problem with the XML serialization.
I want to deserialize and serialize the following xml.
<spec>
<customerAddress>asd</customerAddress>
<OrderIDREF>k1</OrderIDREF>
<OrderIDREFS>k1 k2</OrderIDREFS>
</spec>
The orders that are referenced have the id (eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//ID" iD="true")
The orderIDREF reference works fine with this annotation
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="OrderIDREF"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
The issue is the orderIDREFS reference. I figured out that kind element only works with single references so i tried group and elementWildcard. They also work when loading the xml but when saving it, it always moves the entry into the spec tag like this
<spec OrderIDREFS="k1 k2">
<customerAddress>asd</customerAddress>
<OrderIDREF>k1</OrderIDREF>
</spec>
When i want to load this again it fails with "Feature 'OrderIDREFS' not found"
Is there any setting that I can make to force it to leave it in its own tag?
Thank you
[Updated on: Mon, 29 May 2017 11:00] Report message to a moderator
|
|
|
|
|
|
|
|
Re: XML serialization [message #1764436 is a reply to message #1764432] |
Mon, 29 May 2017 16:57 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
You can use IDREFS as the type but also include ecore:reference="qname" to refer to the complex type you want it to really be. That should work, though the model will include an intermediate "holder" class. E.g., this sort of works but the ecore:eOpposite are invalid because holder class holds the reference...<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.eclipse.org/Library"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:lib="http://www.example.eclipse.org/Library"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Book">
<xsd:sequence>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="pages" type="xsd:int"/>
<xsd:element name="category" type="lib:BookCategory"/>
<xsd:element name="author" type="xsd:IDREF"
ecore:reference="lib:Writer" ecore:opposite="books"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Writer">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="books"
type="xsd:IDREFS" ecore:reference="lib:Book" ecore:opposite="author"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Library">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="writers" type="lib:Writer"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="books" type="lib:Book"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="BookCategory">
<xsd:restriction base="xsd:NCName">
<xsd:enumeration value="Mystery"/>
<xsd:enumeration value="ScienceFiction"/>
<xsd:enumeration value="Biography"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04267 seconds