Skip to main content



      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 09:17 Go to next message
Eclipse UserFriend
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 09:41 Go to previous messageGo to next message
Eclipse UserFriend
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 09:46 Go to previous messageGo to next message
Eclipse UserFriend
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 10:00 Go to previous message
Eclipse UserFriend
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: Mon Jul 14 16:06:13 EDT 2025

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

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

Back to the top