|
|
|
Re: How to extract the corresponding XML for an EObject. [message #423354 is a reply to message #423353] |
Mon, 29 September 2008 12:37 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------040109020307000808030205
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Drew,
Comments below.
drew wrote:
> This only seems to work if the EObject is self-contained (has no references
> to other eobjects) , if the EObject has a field that is a reference to
> another Eobject then I get an exception when the resource gets saved.
>
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: The object
> '.......' is not contained in a resource.
>
Well yes, if you want someone else to read it, it won't do them a lot of
good if there are references to other things you don't send to them.
> Here is the snippet I use to save the resource to a string, maybe there is
> another option that should be specified?
> ///////////snip
> List theList = new ArrayList();
> theList.add(theType);
> Map options = new HashMap();
> options.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
> options.put(XMLResource.OPTION_ROOT_OBJECTS, theList);
> StringWriter o = new StringWriter();
> XMLResource theRes = (XMLResource) theType.eResource();
> theRes.save(o, options);
> String s = o.getBuffer().toString();
> System.out.println(s);
>
You could use this option to discard the dangling references:
* This can be one of "THROW", "DISCARD", "RECORD", where "THROW"
is the default.
*/
String OPTION_PROCESS_DANGLING_HREF =
"PROCESS_DANGLING_HREF";
String OPTION_PROCESS_DANGLING_HREF_THROW = "THROW";
String OPTION_PROCESS_DANGLING_HREF_DISCARD = "DISCARD";
String OPTION_PROCESS_DANGLING_HREF_RECORD = "RECORD";
>
>
> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
> news:gbjasb$tmq$1@build.eclipse.org...
> Drew,
>
> You could use
>
> /**
> * Write only the subtree starting at the specified list of EObjects,
> * which must be objects contained by the resource.
> */
> String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";
>
>
> drew wrote:
> ie. I am rendering the XML fragment for an EObject so that it be printed and
> or passed to other clinets in a string. Is there a way to do this?
>
>
>
>
>
>
--------------040109020307000808030205
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Drew,<br>
<br>
Comments below.<br>
<br>
drew wrote:
<blockquote cite="mid:gbqhrs$h4r$1@build.eclipse.org" type="cite">
<pre wrap="">This only seems to work if the EObject is self-contained (has no references
to other eobjects) , if the EObject has a field that is a reference to
another Eobject then I get an exception when the resource gets saved.
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: The object
'.......' is not contained in a resource.
</pre>
</blockquote>
Well yes, if you want someone else to read it, it won't do them a lot
of good if there are references to other things you don't send to them.<br>
<blockquote cite="mid:gbqhrs$h4r$1@build.eclipse.org" type="cite">
<pre wrap="">
Here is the snippet I use to save the resource to a string, maybe there is
another option that should be specified?
///////////snip
List theList = new ArrayList();
theList.add(theType);
Map options = new HashMap();
options.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
options.put(XMLResource.OPTION_ROOT_OBJECTS, theList);
StringWriter o = new StringWriter();
XMLResource theRes = (XMLResource) theType.eResource();
theRes.save(o, options);
String s = o.getBuffer().toString();
System.out.println(s);
</pre>
</blockquote>
You could use this option to discard the dangling references:<small><br>
</small>
<blockquote><small> * This can be one of "THROW", "DISCARD",
"RECORD", where "THROW" is the default.</small><br>
<small> */</small><br>
<small> String OPTION_PROCESS_DANGLING_HREF &a mp;nbsp; =
"PROCESS_DANGLING_HREF";</small><br>
<small> String OPTION_PROCESS_DANGLING_HREF_THROW &n bsp; = "THROW";</small><br>
<small> String OPTION_PROCESS_DANGLING_HREF_DISCARD = "DISCARD";</small><br>
<small> String OPTION_PROCESS_DANGLING_HREF_RECORD = "RECORD";</small><br>
</blockquote>
<blockquote cite="mid:gbqhrs$h4r$1@build.eclipse.org" type="cite">
<pre wrap="">
"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:Ed.Merks@gmail.com"><Ed.Merks@gmail.com></a> wrote in message
<a class="moz-txt-link-freetext" href="news:gbjasb$tmq$1@build.eclipse.org">news:gbjasb$tmq$1@build.eclipse.org</a>...
Drew,
You could use
/**
* Write only the subtree starting at the specified list of EObjects,
* which must be objects contained by the resource.
*/
String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";
drew wrote:
ie. I am rendering the XML fragment for an EObject so that it be printed and
or passed to other clinets in a string. Is there a way to do this?
</pre>
</blockquote>
</body>
</html>
--------------040109020307000808030205--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03453 seconds