Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » access element contents as raw text?
access element contents as raw text? [message #425877] Wed, 10 December 2008 18:58 Go to next message
Matthias is currently offline MatthiasFriend
Messages: 3
Registered: July 2009
Junior Member
Hello,

we are using EMF to process XML documents based on an XML schema. The XML
includes elements named "<plugin>" that can contain arbitrary content:

<x:plugin name="123">
... unknown arbitrary content structured by sub-elements ...
</x:plugin>

The <plugin> element is defined in the XML schema and it has been
generated into the ECore model.

In our application, we need to get the content of the <plugin> element as
pure, raw text (i.e. simply the text fragment as given in the XML) in
order to pass it to an external component. In this case, we do not need to
deal with a FeatureMap etc.

Is there any way to access the raw text with EMF?

We are flexible concerning the XML schema definition of <plugin>. The only
requirement is that it must allow arbitrary content structured by
sub-elements. A mixed content would also be OK. We already tried a
complexType with simpleContent based by xs:string, and xs:any.

Regards,
Matthias
Re: access element contents as raw text? [message #425879 is a reply to message #425877] Wed, 10 December 2008 19:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010908080501090304020901
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Matthias,

Comments below.

Matthias wrote:
> Hello,
>
> we are using EMF to process XML documents based on an XML schema. The
> XML includes elements named "<plugin>" that can contain arbitrary
> content:
> <x:plugin name="123">
> ... unknown arbitrary content structured by sub-elements ...
> </x:plugin>
>
> The <plugin> element is defined in the XML schema and it has been
> generated into the ECore model.
> In our application, we need to get the content of the <plugin> element
> as pure, raw text (i.e. simply the text fragment as given in the XML)
> in order to pass it to an external component. In this case, we do not
> need to deal with a FeatureMap etc.
> Is there any way to access the raw text with EMF?
This option is useful for serializing just a subgraph of the whole resource:

/**
* 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";

Note also that it's possible to serialize directly to a Writer rather
than to an OutputStream to save the encoding/decoding cots.
> We are flexible concerning the XML schema definition of <plugin>. The
> only requirement is that it must allow arbitrary content structured by
> sub-elements. A mixed content would also be OK. We already tried a
> complexType with simpleContent based by xs:string, and xs:any.
With the above approach, you can design the complex type however it
makes sense...
>
> Regards,
> Matthias
>

--------------010908080501090304020901
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Matthias,<br>
<br>
Comments below.<br>
<br>
Matthias wrote:
<blockquote
cite="mid:825bd1cba41f41dd47441508236d5117$1@www.eclipse.org"
type="cite">Hello,
<br>
<br>
we are using EMF to process XML documents based on an XML schema. The
XML includes elements named "&lt;plugin&gt;" that can contain arbitrary
content: <br>
&lt;x:plugin name="123"&gt;
<br>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: access element contents as raw text? [message #426116 is a reply to message #425879] Tue, 16 December 2008 17:59 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 3
Registered: July 2009
Junior Member
Hello Ed,

thanks for your help.

Unfortunately, we couldn't manage to get the raw text serialization of
only one of our EObjects. We couldn't find out how/when/where to use
OPTION_ROOT_OBJECTS parameter. Could you provide a short code example of
how to do it?

Thanks in advance,
Matthias
Re: access element contents as raw text? [message #426121 is a reply to message #426116] Tue, 16 December 2008 21:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Matthias,

Like this:

Resource resource =
resourceSet.createResource(URI.createURI("http:///My.library"));
DocumentRoot documentRoot =
LibraryFactory.eINSTANCE.createDocumentRoot();
Library root = LibraryFactory.eINSTANCE.createLibrary();
Book book = LibraryFactory.eINSTANCE.createBook();
root.getBooks().add(book);
documentRoot.setLibrary(root);
resource.getContents().add(documentRoot);
resource.save(System.out, null);
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ROOT_OBJECTS,
Collections.singletonList(book));
resource.save(System.out, options);

Of course if you element doesn't correspond to a global element, the
serialization won't be schema-valid.


Matthias wrote:
> Hello Ed,
>
> thanks for your help.
> Unfortunately, we couldn't manage to get the raw text serialization of
> only one of our EObjects. We couldn't find out how/when/where to use
> OPTION_ROOT_OBJECTS parameter. Could you provide a short code example
> of how to do it?
>
> Thanks in advance,
> Matthias
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] About revisions
Next Topic:Does merging re-gen support not overwriting interfaces added to the generated classes?
Goto Forum:
  


Current Time: Fri Apr 26 17:48:08 GMT 2024

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

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

Back to the top