Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Tell me the name of...(XML options...)
Tell me the name of... [message #842582] Thu, 12 April 2012 12:36 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
currently my resource export saves the xml in this format:
<object guid="GUID0123456789">
  <subobject guid="GUID0123456789" name="lumo" email="l@mymail.at" version="1.0"/>
</object>


which options do i have to set so it gets stored like that:
<object>
    <guid>GUID0123456789</guid>
    <subobject>
    <guid>GUID0123456789</guid>
    <name>lumo</name>
    <email>l@mymail.at</email>
    <version>1.0</version>
  </subobject>
</object>


i create the xml with this code:
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,	new XMLResourceFactoryImpl());

try {
	// test creating some xml
	URI xmlUri = URI.createFileURI(new File("xml/model.xml").getAbsolutePath());
	System.out.println("xml: " + xmlUri);
	Resource resource = resourceSet.createResource(xmlUri);
	resource.getContents().add(getData()); // getData() gets my data model instance
	Map<String, Object> options = new HashMap<String, Object>();
	options.put(XMLResource.OPTION_ENCODING, "UTF-8");
	// save to file
	resource.save(options);
	// print to console
	resource.save(System.out, options);
} catch (IOException exception) {
	exception.printStackTrace();
}


i guess this is an option that i have to add to my options-map, but i have no clue what this is called...
thanks in advance!
Re: Tell me the name of... [message #845625 is a reply to message #842582] Sun, 15 April 2012 08:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Ludwig,

Comments below.

On 12/04/2012 2:36 PM, Ludwig Moser wrote:
> currently my resource export saves the xml in this format:
>
> <object guid="GUID0123456789">
> <subobject guid="GUID0123456789" name="lumo" email="l@xxxxxxxx"
> version="1.0"/>
> </object>
>
>
> which options do i have to set so it gets stored like that:
>
> <object>
> <guid>GUID0123456789</guid>
> <subobject>
> <guid>GUID0123456789</guid>
> <name>lumo</name>
> <email>l@xxxxxxxx</email>
> <version>1.0</version>
> </subobject>
> </object>
You need extended meta data annotations to tailor the serialization.
But is sounds like you're starting with an XSD. In that case you should
have a generated resource factory that does the right things; you're
just not using it in the code you showed. Use Generate Test Code and
look at the generated XyzExample.java.
>
>
> i create the xml with this code:
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMLResourceFactoryImpl());
>
> try {
> // test creating some xml
> URI xmlUri = URI.createFileURI(new
> File("xml/model.xml").getAbsolutePath());
> System.out.println("xml: " + xmlUri);
> Resource resource = resourceSet.createResource(xmlUri);
> resource.getContents().add(getData()); // getData() gets my data
> model instance
> Map<String, Object> options = new HashMap<String, Object>();
> options.put(XMLResource.OPTION_ENCODING, "UTF-8");
> // save to file
> resource.save(options);
> // print to console
> resource.save(System.out, options);
> } catch (IOException exception) {
> exception.printStackTrace();
> }
>
>
> i guess this is an option that i have to add to my options-map, but i
> have no clue what this is called...
> thanks in advance!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Tell me the name of... [message #845640 is a reply to message #845625] Sun, 15 April 2012 08:51 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
Actually the code above is taken out of one of the generated test cases!
The xsd file i got is generated from the ecore model

So my starting point is the ecore where i generated the xsd from
Then i generated the test case, took the file and modded the code to export to xml instead of xmi...

So how should the meta data annotations look like?
Iff its too much work i write an exporter to mdb (access)

[Updated on: Sun, 15 April 2012 08:51]

Report message to a moderator

Re: Tell me the name of... [message #845664 is a reply to message #845640] Sun, 15 April 2012 09:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Ludwig,

Comments below.

On 15/04/2012 10:51 AM, Ludwig Moser wrote:
> Actually the code above is taken out of one of the generated test cases!
I assumed you started with an XSD, but that's apparently not that case.
> The xsd file i got is generated from the ecore model
>
> So my starting point is the ecore where i generated the xsd from
> Then i generated the test case, took the file and modded the code to
> export to xml instead of xmi...
It's probably easier if you take the schema you have, modify it so it
uses elements instead of attributes where you want that, and then use
that model to create your GenModel/Ecore model. This way you'll have
all the right annotations.
>
> So how should the meta data annotations look like?
> Iff its too much work i write an exporter to mdb (access)


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Tell me the name of... [message #846631 is a reply to message #845664] Mon, 16 April 2012 11:55 Go to previous message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
xsd i created from my ecore model uses ONLY elements, as the roots.
then every element (Type) got only attributes. if i change the src-code xsd:attribute to xsd:element it tells me its not allowed at that place.
or am i doing the wrong thing?
Previous Topic:Are Change.ecore, UML.ecore and bpmn.ecore valid?
Next Topic:[Texo] error while generating JPA Annotated model
Goto Forum:
  


Current Time: Fri Apr 19 23:17:16 GMT 2024

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

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

Back to the top