access element contents as raw text? [message #425877] |
Wed, 10 December 2008 13:58  |
Eclipse User |
|
|
|
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 14:10   |
Eclipse User |
|
|
|
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 "<plugin>" that can contain arbitrary
content: <br>
<x:plugin name="123">
<br>
|
|
|
|
Re: access element contents as raw text? [message #426121 is a reply to message #426116] |
Tue, 16 December 2008 16:52  |
Eclipse User |
|
|
|
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
>
|
|
|
Powered by
FUDForum. Page generated in 0.40010 seconds