|
|
|
|
|
|
|
Re: retain order of XML elements when using EMF [message #1806790 is a reply to message #1806766] |
Wed, 15 May 2019 08:18 |
Zakir Meer Messages: 50 Registered: February 2016 |
Member |
|
|
Hi Ed,
sorry for the confusion.
Based on your previous reply, I tried creating a more complex example by modifying the xml schema and generated corresponding EMF model from it. But somehow I missed to attach it while I was replying to your message.
Please find the XML schema (latest) which allows to mix orderperson tag
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="orderperson" type="xs:string" maxOccurs="unbounded" />
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="address" type="xs:string" />
<xs:element name="city" type="xs:string" />
<xs:element name="country" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="note" type="xs:string" minOccurs="0" />
<xs:element name="quantity" type="xs:positiveInteger" />
<xs:element name="price" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
In between I used JDOM2 to check my expectations and this is working as expected (i.e. order of the retrieval of the mixed elements is same as present in the xml)
In case of EMF, still I do not get the right results, as the retrieval is based on EAllStructuralFeatures which will give only unique list and can not handle the scenarios if different XML elements are mixed.
shipOrderEObject.eClass()
.getEAllStructuralFeatures())
Below is the result of execution:
<orderperson>=[John Smith, smith, john]
<shipto>=[Sample.impl.ShiptoTypeImpl@2f9f7dcf (name: Ola Nordmann, address: Langgt 23, city: 4000 Stavanger, country: Norway)]
<item>=[Sample.impl.ItemTypeImpl@747ddf94 (title: Empire Burlesque, note: Special Edition, quantity: 1, price: 10.90), Sample.impl.ItemTypeImpl@1bd4fdd (title: Hide your heart, note: null, quantity: 1, price: 9.90)]
orderid='889923'
FYI : I have attached the source code containing test case of EMF loading and JDOM2 loading.
p.s: I am a big fan of EMF and would prefer to use EMF for XML handling.. rather than using other XML dom technologies !! I guess there is a gap in the EMF API w.r..t fetching XML contents (in the same order they are defined in the file ) and due to this reason I am trying to clarify. I hope you do not take me in the other way :P
[Updated on: Wed, 15 May 2019 09:13] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03272 seconds