|
Re: Saving model instance to XML with XSD? [message #845624 is a reply to message #842497] |
Sun, 15 April 2012 08:27 |
Ed Merks 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<String, String> options = new HashMap<String,
String>();
<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... -> later this xsd _could_ be located on a webserver)
<br>
</blockquote>
</body>
</html>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04072 seconds