Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Saving model instance to XML with XSD?
Saving model instance to XML with XSD? [message #842497] Thu, 12 April 2012 10:57 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
Hello!

i figured out how to save the instance of my model to XML (with correct encoding)

but how can i add the XSD to my XML file?
i have the XSD in a seperate file and want to either link the xsd in the xml.

i tried:
URI xmlUri = URI.createFileURI(new File("xml/model.xml").getAbsolutePath());
URI xsdUri = URI.createFileURI(new File("xml/model.xsd").getAbsolutePath());
System.out.println("xml: " + xmlUri);
System.out.println("xsd: " + xsdUri.toString());
Resource resource = resourceSet.createResource(xmlUri);
resource.getContents().add(instanceModel); // adding my instances to the resource
Map<String, String> options = new HashMap<String, String>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8"); // set encoding to utf-8
// options.put(XMLResource.OPTION_SCHEMA_LOCATION, xsdUri.toString()); // not working
options.put(XMLResource.OPTION_SCHEMA_LOCATION_IMPLEMENTATION, ServerPackage.eINSTANCE.getNsURI()); // not working
// save to file
resource.save(options);
// print to console
resource.save(System.out, options);


how can i put those things together? (note that the xsd file is located at this place always, its not generated when you save the xml... -> later this xsd _could_ be located on a webserver)
Re: Saving model instance to XML with XSD? [message #845624 is a reply to message #842497] Sun, 15 April 2012 08:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33139
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<ul>
<li class="toclevel-2"><a
href="http://wiki.eclipse.org/index.php/EMF-FAQ#How_can_I_ensure_that_an_xsi:schemaLocation_is_serialized_for_my_packages.3F"><span
class="tocnumber">2.22</span> <span class="toctext">How can
I ensure that an xsi:schemaLocation is serialized for my
packages?</span></a></li>
</ul>
<br>
<br>
On 12/04/2012 12:57 PM, Ludwig Moser wrote:
<blockquote cite="mid:jm6ce4$4qa$1@xxxxxxxxe.org" type="cite">Hello!
<br>
<br>
i figured out how to save the instance of my model to XML (with
correct encoding)
<br>
<br>
but how can i add the XSD to my XML file?
<br>
i have the XSD in a seperate file and want to either link the xsd
in the xml.
<br>
<br>
i tried:
<br>
<br>
URI xmlUri = URI.createFileURI(new
File("xml/model.xml").getAbsolutePath());
<br>
URI xsdUri = URI.createFileURI(new
File("xml/model.xsd").getAbsolutePath());
<br>
System.out.println("xml: " + xmlUri);
<br>
System.out.println("xsd: " + xsdUri.toString());
<br>
Resource resource = resourceSet.createResource(xmlUri);
<br>
resource.getContents().add(instanceModel); // adding my instances
to the resource
<br>
Map&lt;String, String&gt; options = new HashMap&lt;String,
String&gt;();
<br>
options.put(XMLResource.OPTION_ENCODING, "UTF-8"); // set encoding
to utf-8
<br>
// options.put(XMLResource.OPTION_SCHEMA_LOCATION,
xsdUri.toString()); // not working
<br>
options.put(XMLResource.OPTION_SCHEMA_LOCATION_IMPLEMENTATION,
ServerPackage.eINSTANCE.getNsURI()); // not working
<br>
// save to file
<br>
resource.save(options);
<br>
// print to console
<br>
resource.save(System.out, options);
<br>
<br>
<br>
how can i put those things together? (note that the xsd file is
located at this place always, its not generated when you save the
xml... -&gt; later this xsd _could_ be located on a webserver)
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Using object from one transaction in antother transaction
Next Topic:[CDO][Hibernate] org.hibernate.hql.ast.QuerySyntaxException: MyModelClass is not mapped [from MyMode
Goto Forum:
  


Current Time: Tue Apr 23 06:21:51 GMT 2024

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

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

Back to the top