Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF: mixed complex type generates invalid XML(elements in mixed complex type in incorrect order)
EMF: mixed complex type generates invalid XML [message #1075465] Mon, 29 July 2013 13:25 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Ed,

I have stumbled accross a small issue with mixed that I would be very grateful of your opinion and assistance.

If I have a schema as follows:

  <xs:element name="student">
	<xs:complexType mixed="true">
	<xs:sequence>
		<xs:element name="name" type="xs:string"/>
		<xs:element name="age" type="xs:positiveInteger"/>
	</xs:sequence>
	</xs:complexType>
</xs:element>


It will generate all the classes OK, so if I then code something like:

	studentType createStudent = MixedContentFactory.eINSTANCE.createstudentType();
	createStudent.setName("Bully Bogywart");
	createStudent.setAge(new BigInteger("18"));


then I will get the expected XML of:

<content:student xmlns:content="http://example.com/MixedContent">
    <name>Bully Bogywart</name>
    <age>18</age>
</content:student>


However, if I set the elements in a more random order:

	studentType createStudent = MixedContentFactory.eINSTANCE.createstudentType();
	createStudent.setAge(new BigInteger("18"));
	createStudent.setName("Bully Bogywart");


Then it will generate the following XML:

<content:student xmlns:content="http://example.com/MixedContent">
    <age>18</age>
    <name>Bully Bogywart</name>
</content:student>


Which seems to reflect the order in which they were added, but not the valid order as specified in the schema.

Do you have any ideas or pointers as to what might be causing this?

Thanks

Rob
Re: EMF: mixed complex type generates invalid XML [message #1075493 is a reply to message #1075465] Mon, 29 July 2013 14:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Rob,

Comments below.

On 29/07/2013 3:25 PM, Rob Mising name wrote:
> Hi Ed,
>
> I have stumbled accross a small issue with mixed that I would be very
> grateful of your opinion and assistance.
>
> If I have a schema as follows:
>
> <xs:element name="student">
> <xs:complexType mixed="true">
> <xs:sequence>
> <xs:element name="name" type="xs:string"/>
> <xs:element name="age" type="xs:positiveInteger"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
>
> It will generate all the classes OK, so if I then code something like:
>
> studentType createStudent =
> MixedContentFactory.eINSTANCE.createstudentType();
> createStudent.setName("Bully Bogywart");
> createStudent.setAge(new BigInteger("18"));
The order will be recorded in the feature map...
>
>
> then I will get the expected XML of:
>
> <content:student xmlns:content="http://example.com/MixedContent">
> <name>Bully Bogywart</name>
> <age>18</age>
> </content:student>
>
>
> However, if I set the elements in a more random order:
>
> studentType createStudent =
> MixedContentFactory.eINSTANCE.createstudentType();
> createStudent.setAge(new BigInteger("18"));
> createStudent.setName("Bully Bogywart");
>
>
> Then it will generate the following XML:
>
> <content:student xmlns:content="http://example.com/MixedContent">
> <age>18</age>
> <name>Bully Bogywart</name>
> </content:student>
Yes, it's unfortunate but there's no information recorded about the
"correct" order: https://bugs.eclipse.org/bugs/show_bug.cgi?id=51210
>
>
> Which seems to reflect the order in which they were added, but not the
> valid order as specified in the schema.
Yes.
>
> Do you have any ideas or pointers as to what might be causing this?
It's just the way it is. XML Schema allows all sorts of complexity in
the particle structure that's not recorded, not checked, and not
available for trying to maintain a correct order. It's an unfortunate
limitation of the current design.
>
> Thanks
>
> Rob
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF: mixed complex type generates invalid XML [message #1086495 is a reply to message #1075465] Wed, 14 August 2013 09:17 Go to previous message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Ed,

Thanks for all the information.

I think I have now implemented a suitable workaround, just in case anyone is interested (or finds themself needed to support this as well) I thought that I'd post here how we got around this behaviour.

1) Update the eCore so that there is an annotation on any elements within Complex Types which have the mixed value against them. This annotation (we called it "SequenceOrder") just has a numeric value in it stating the order. In theory you could add it to ExtendedMetadata, but we added our own new section. [Also note that in cases of inheritance, your numbering needs to take account of anything in the super types]

2) Overload the existing FeatureMap so that you are able to customise it a little - you can get this picked up by setting the GenModel so that "Model Feature Defaults -> Feature Map Wrapper" points to your Wrapper implementation class.

3) In your FeatureMap whenever an add or set is done where an index position is not given, after the default code has been run for the add/set method, move the item from the end of the list to the position given to it by the "SequenceOrder" defined in step 1. (There is already a move operation available that takes two indexes). You will obviously have to work through the existing elements to work out where in the order it will go.

After that - you should be able to programatically set each element in any order, and the featureMap behind it automatically store things in the valid order for the schema.

Hope that this sort of makes sense.

Rob
Previous Topic:EClassifier ordering in generated EPackages
Next Topic:[CDO] Create an offline Server
Goto Forum:
  


Current Time: Sat Apr 27 04:58:47 GMT 2024

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

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

Back to the top