Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » sorting the serialized objects in xml(sorting the serialized objects in xml)
sorting the serialized objects in xml [message #1741633] Fri, 26 August 2016 13:17 Go to next message
naveen ramesh is currently offline naveen rameshFriend
Messages: 56
Registered: May 2016
Member
Hi,
I have designed an ecore model which has the class Student which contains the parameter student-name .Now I have around 10 student instances and when i serialize the objects into xml i want the nodes to be sorted based on the student-name. So how can we sort the xml serialized object based on student-name in xml.

OR If the xml has serialized object how can we sort based on the name and save the xml file.
Re: sorting the serialized objects in xml [message #1741639 is a reply to message #1741633] Fri, 26 August 2016 13:41 Go to previous messageGo to next message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
Hello,

During serialization, the order of the list is kept. So I think you just have to use a simple Java comparator to sort the EList that contains your students :

Collections.sort(lesson.getStudents(), new Comparator<Student>()
{
	@Override
	public int compare(Student o1, Student o2)
	{
		return o1.getName().compareTo(o2.getName());
	}
});


Now the question is : when do you want the sort append ? Automatically when you add a student, or when you execute a command ? Or just before a save ?
Re: sorting the serialized objects in xml [message #1741640 is a reply to message #1741639] Fri, 26 August 2016 13:46 Go to previous messageGo to next message
naveen ramesh is currently offline naveen rameshFriend
Messages: 56
Registered: May 2016
Member
when we execute the command .Also we are using transaction editing domain and for sorting we are using Ecollection.sort but it is throwing unsupported operation exception.
Re: sorting the serialized objects in xml [message #1741641 is a reply to message #1741640] Fri, 26 August 2016 14:00 Go to previous message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
I never used ECollections.sort, but I suppose the use is the same than Collections.sort

I don't now why you got an UnsuportedOperationException, you should post your code here, and the stack trace if relevant.
Previous Topic:[Xcore/2] circular dependencies
Next Topic:[CDO] Cannot create root element from my model
Goto Forum:
  


Current Time: Thu Apr 25 11:03:55 GMT 2024

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

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

Back to the top