Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to extract the corresponding XML for an EObject.
How to extract the corresponding XML for an EObject. [message #423306] Fri, 26 September 2008 17:56 Go to next message
drew frantz is currently offline drew frantz
Messages: 340
Registered: July 2009
Senior Member
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?
Re: How to extract the corresponding XML for an EObject. [message #423307 is a reply to message #423306] Fri, 26 September 2008 18:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010409070700090100060102
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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?
>
>
>

--------------010409070700090100060102
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>
You could use <small><br>
</small>
<blockquote><small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * Write only the subtree starting at the specified list of
EObjects, </small><br>
<small>&nbsp;&nbsp; * which must be objects contained by the resource.</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";</small><br>
</blockquote>
<br>
drew wrote:
<blockquote cite="mid:gbj7no$8cr$1@build.eclipse.org" type="cite">
<pre wrap="">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>

--------------010409070700090100060102--
Re: How to extract the corresponding XML for an EObject. [message #423353 is a reply to message #423307] Mon, 29 September 2008 12:31 Go to previous messageGo to next message
drew frantz is currently offline drew frantz
Messages: 340
Registered: July 2009
Senior Member
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.

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);



"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?
Re: How to extract the corresponding XML for an EObject. [message #423354 is a reply to message #423353] Mon, 29 September 2008 12:37 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26141
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>&nbsp;&nbsp; * This can be one of "THROW", "DISCARD",
"RECORD", where "THROW" is the default.</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; String OPTION_PROCESS_DANGLING_HREF&nbsp;&nbsp;&nbsp;&a mp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
"PROCESS_DANGLING_HREF";</small><br>
<small>&nbsp; String OPTION_PROCESS_DANGLING_HREF_THROW&nbsp;&nbsp;&n bsp; = "THROW";</small><br>
<small>&nbsp; String OPTION_PROCESS_DANGLING_HREF_DISCARD&nbsp; = "DISCARD";</small><br>
<small>&nbsp; String OPTION_PROCESS_DANGLING_HREF_RECORD&nbsp;&nbsp; = "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">&lt;Ed.Merks@gmail.com&gt;</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--
Previous Topic:Wrapping character values using SimleAnyType
Next Topic:CDO resourceSet
Goto Forum:
  


Current Time: Sat Oct 25 19:17:59 GMT 2014

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

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