Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Formatted Text Serialization in XML
Formatted Text Serialization in XML [message #392541] Tue, 26 April 2005 12:44 Go to next message
Joe Shultz is currently offline Joe Shultz
Messages: 3
Registered: July 2009
Junior Member
Hello,



I have created an EMF model, and among other things, I've added a few
EAttributes of type EString. I am using this EString to hold text that is
formatted with whitespace (spaces, tabs, cartridge returns). When the model
is persisted via XML and then re-opened, all of the whitespace characters
are converted into a single space, so I am losing all my formatting.



I've tried (without success) to set extended metadata options to preserve
this whitespace. I created a ResourceImpl and tried to override the
createXMLHelper() method to add support for preserving whitespace:



public class DesignResourceImpl extends XMIResourceImpl {
protected XMLHelper createXMLHelper() {
XMLHelper h = super.createXMLHelper();
ExtendedMetaData emd = h.getExtendedMetaData();
if (emd == null)
{
emd = new BasicExtendedMetaData();
}

emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitialization
().eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);

emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().eC
ontainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);

emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization()
..eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
h.setExtendedMetaData(emd);
return h;
}

....

}



This doesn't seem to have any effect. Does anyone know the proper way to
preserve this formatted text?



Thanks!

- Joe
Re: Formatted Text Serialization in XML [message #392543 is a reply to message #392541] Tue, 26 April 2005 13:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 24564
Registered: July 2009
Senior Member
Joe,

If it's serialized as an XML attribute, you can't (as far as I know)
prevent the XML parser from collapsing the white space. You'll need to
serialize it as an element, which you can do by setting the feature kind
to be ELEMENT_FEATURE.


Joe Shultz wrote:

>Hello,
>
>
>
>I have created an EMF model, and among other things, I've added a few
>EAttributes of type EString. I am using this EString to hold text that is
>formatted with whitespace (spaces, tabs, cartridge returns). When the model
>is persisted via XML and then re-opened, all of the whitespace characters
>are converted into a single space, so I am losing all my formatting.
>
>
>
>I've tried (without success) to set extended metadata options to preserve
>this whitespace. I created a ResourceImpl and tried to override the
>createXMLHelper() method to add support for preserving whitespace:
>
>
>
>public class DesignResourceImpl extends XMIResourceImpl {
> protected XMLHelper createXMLHelper() {
> XMLHelper h = super.createXMLHelper();
> ExtendedMetaData emd = h.getExtendedMetaData();
> if (emd == null)
> {
> emd = new BasicExtendedMetaData();
> }
>
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitialization
>().eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
>
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().eC
>ontainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
>
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization()
>.eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
> h.setExtendedMetaData(emd);
> return h;
> }
>
>...
>
>}
>
>
>
>This doesn't seem to have any effect. Does anyone know the proper way to
>preserve this formatted text?
>
>
>
>Thanks!
>
>- Joe
>
>
>
>
Re: Formatted Text Serialization in XML [message #392547 is a reply to message #392543] Tue, 26 April 2005 17:15 Go to previous messageGo to next message
Joe Shultz is currently offline Joe Shultz
Messages: 3
Registered: July 2009
Junior Member
Ed,

Sorry for being dumb but I need some more help. I've tried setting the
feature kind in a number of ways and it keeps getting serialized as an
Attribute rather than an Element. First, I tried adding the following calls
to the XMLHelper() method I described previously:

emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitialization
().eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().eC
ontainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization()
..eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);

but this had no effect. I then searched the newsgroup and found a series of
posts between you and Nima Mazloumi (from Oct 2004). You suggested editing
the ecore file directly, so I tried that:

<eStructuralFeatures xsi:type="ecore:EAttribute"
name="narrowbandInitialization"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
</eAnnotations>
</eStructuralFeatures>

However, it was still serialized as an attribute after re-generating all in
My.genmodel. Can you go into a little more detail in how and where I should
set the feature kind? I am not using Omondo or Rose to help with the
modeling, but at this point I'm willing to try anything.

Thanks for your time,
- Joe


Ed Merks wrote:
> Joe,
>
> If it's serialized as an XML attribute, you can't (as far as I know)
> prevent the XML parser from collapsing the white space. You'll need to
> serialize it as an element, which you can do by setting the feature kind
> to be ELEMENT_FEATURE.
>
>
> Joe Shultz wrote:
>
> >Hello,
> >
> >
> >
> >I have created an EMF model, and among other things, I've added a few
> >EAttributes of type EString. I am using this EString to hold text that is
> >formatted with whitespace (spaces, tabs, cartridge returns). When the
model
> >is persisted via XML and then re-opened, all of the whitespace characters
> >are converted into a single space, so I am losing all my formatting.
> >
> >
> >
> >I've tried (without success) to set extended metadata options to preserve
> >this whitespace. I created a ResourceImpl and tried to override the
> >createXMLHelper() method to add support for preserving whitespace:
> >
> >
> >
> >public class DesignResourceImpl extends XMIResourceImpl {
> > protected XMLHelper createXMLHelper() {
> > XMLHelper h = super.createXMLHelper();
> > ExtendedMetaData emd = h.getExtendedMetaData();
> > if (emd == null)
> > {
> > emd = new BasicExtendedMetaData();
> > }
> >
>
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitializatio
n
> >().eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
> >
>
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().e
C
> >ontainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
> >
>
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization(
)
> >.eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
> > h.setExtendedMetaData(emd);
> > return h;
> > }
> >
> >...
> >
> >}
> >
> >
> >
> >This doesn't seem to have any effect. Does anyone know the proper way to
> >preserve this formatted text?
> >
> >
> >
> >Thanks!
> >
> >- Joe
> >
> >
> >
> >
Re: Formatted Text Serialization in XML [message #392551 is a reply to message #392547] Tue, 26 April 2005 18:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 24564
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020800070807060900000502
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Joe,

What are you using to build your model? You really should set these
annotations so that they are in the .ecore before you generated so that
they will already be there in the generated EPackage. They can even be
expressed in the @model annotations. If you add them to your .ecore
file and generate the Java, you'll see that these annotations are
generated into your Java source.

What I failed to tell you (stupid me not stupid you) is that in order
for these annotations to be respected, you have to use
XMLResource.OPTION_EXTENDED_META_DATA as an option during save.


Joe Shultz wrote:

>Ed,
>
>Sorry for being dumb but I need some more help. I've tried setting the
>feature kind in a number of ways and it keeps getting serialized as an
>Attribute rather than an Element. First, I tried adding the following calls
>to the XMLHelper() method I described previously:
>
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitialization
>().eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().eC
>ontainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization()
>.eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
>
>but this had no effect. I then searched the newsgroup and found a series of
>posts between you and Nima Mazloumi (from Oct 2004). You suggested editing
>the ecore file directly, so I tried that:
>
><eStructuralFeatures xsi:type="ecore:EAttribute"
>name="narrowbandInitialization"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
> <eAnnotations
>source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> </eAnnotations>
></eStructuralFeatures>
>
>However, it was still serialized as an attribute after re-generating all in
>My.genmodel. Can you go into a little more detail in how and where I should
>set the feature kind? I am not using Omondo or Rose to help with the
>modeling, but at this point I'm willing to try anything.
>
>Thanks for your time,
>- Joe
>
>
>Ed Merks wrote:
>
>
>>Joe,
>>
>>If it's serialized as an XML attribute, you can't (as far as I know)
>>prevent the XML parser from collapsing the white space. You'll need to
>>serialize it as an element, which you can do by setting the feature kind
>>to be ELEMENT_FEATURE.
>>
>>
>>Joe Shultz wrote:
>>
>>
>>
>>>Hello,
>>>
>>>
>>>
>>>I have created an EMF model, and among other things, I've added a few
>>>EAttributes of type EString. I am using this EString to hold text that is
>>>formatted with whitespace (spaces, tabs, cartridge returns). When the
>>>
>>>
>model
>
>
>>>is persisted via XML and then re-opened, all of the whitespace characters
>>>are converted into a single space, so I am losing all my formatting.
>>>
>>>
>>>
>>>I've tried (without success) to set extended metadata options to preserve
>>>this whitespace. I created a ResourceImpl and tried to override the
>>>createXMLHelper() method to add support for preserving whitespace:
>>>
>>>
>>>
>>>public class DesignResourceImpl extends XMIResourceImpl {
>>>protected XMLHelper createXMLHelper() {
>>> XMLHelper h = super.createXMLHelper();
>>> ExtendedMetaData emd = h.getExtendedMetaData();
>>> if (emd == null)
>>> {
>>> emd = new BasicExtendedMetaData();
>>> }
>>>
>>>
>>>
>> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitializatio
>>
>>
>n
>
>
>>>().eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
>>>
>>>
>>>
>> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().e
>>
>>
>C
>
>
>>>ontainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
>>>
>>>
>>>
>> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization(
>>
>>
>)
>
>
>>>.eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
>>> h.setExtendedMetaData(emd);
>>> return h;
>>>}
>>>
>>>...
>>>
>>>}
>>>
>>>
>>>
>>>This doesn't seem to have any effect. Does anyone know the proper way to
>>>preserve this formatted text?
>>>
>>>
>>>
>>>Thanks!
>>>
>>>- Joe
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------020800070807060900000502
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">
Joe,<br>
<br>
What are you using to build your model?&nbsp; You really should set these
annotations so that they are in the .ecore before you generated so that
they will already be there in the generated EPackage.&nbsp;&nbsp; They can even
be expressed in the @model annotations.&nbsp; If you add them to your .ecore
file and generate the Java, you'll see that these annotations are
generated into your Java source.<br>
<br>
What I failed to tell you (stupid me not stupid you) is that in order
for these annotations to be respected,&nbsp; you have to use
XMLResource.OPTION_EXTENDED_META_DATA as an option during save. <br>
<br>
<br>
Joe Shultz wrote:
<blockquote cite="midd4mb6i$sl1$1@news.eclipse.org" type="cite">
<pre wrap="">Ed,

Sorry for being dumb but I need some more help. I've tried setting the
feature kind in a number of ways and it keeps getting serialized as an
Attribute rather than an Element. First, I tried adding the following calls
to the XMLHelper() method I described previously:

emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitialization
().eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().eC
ontainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization()
..eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);

but this had no effect. I then searched the newsgroup and found a series of
posts between you and Nima Mazloumi (from Oct 2004). You suggested editing
the ecore file directly, so I tried that:

&lt;eStructuralFeatures xsi:type="ecore:EAttribute"
name="narrowbandInitialization"
eType="ecore:EDataType <a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2002/Ecore#//EString">http://www.eclipse.org/emf/2002/Ecore#//EString</a>"&gt;
&lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
&lt;details key="kind" value="element"/&gt;
&lt;/eAnnotations&gt;
&lt;/eStructuralFeatures&gt;

However, it was still serialized as an attribute after re-generating all in
My.genmodel. Can you go into a little more detail in how and where I should
set the feature kind? I am not using Omondo or Rose to help with the
modeling, but at this point I'm willing to try anything.

Thanks for your time,
- Joe


Ed Merks wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Joe,

If it's serialized as an XML attribute, you can't (as far as I know)
prevent the XML parser from collapsing the white space. You'll need to
serialize it as an element, which you can do by setting the feature kind
to be ELEMENT_FEATURE.


Joe Shultz wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Hello,



I have created an EMF model, and among other things, I've added a few
EAttributes of type EString. I am using this EString to hold text that is
formatted with whitespace (spaces, tabs, cartridge returns). When the
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->model
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">is persisted via XML and then re-opened, all of the whitespace characters
are converted into a single space, so I am losing all my formatting.



I've tried (without success) to set extended metadata options to preserve
this whitespace. I created a ResourceImpl and tried to override the
createXMLHelper() method to add support for preserving whitespace:



public class DesignResourceImpl extends XMIResourceImpl {
protected XMLHelper createXMLHelper() {
XMLHelper h = super.createXMLHelper();
ExtendedMetaData emd = h.getExtendedMetaData();
if (emd == null)
{
emd = new BasicExtendedMetaData();
}

</pre>
</blockquote>
<pre wrap=""> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitializatio
</pre>
</blockquote>
<pre wrap=""><!---->n
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">().eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);

</pre>
</blockquote>
<pre wrap=""> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().e
</pre>
</blockquote>
<pre wrap=""><!---->C
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ontainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);

</pre>
</blockquote>
<pre wrap=""> emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization(
</pre>
</blockquote>
<pre wrap=""><!---->)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">.eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
h.setExtendedMetaData(emd);
return h;
}

....

}



This doesn't seem to have any effect. Does anyone know the proper way to
preserve this formatted text?



Thanks!

- Joe




</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------020800070807060900000502--
Re: Formatted Text Serialization in XML [message #392564 is a reply to message #392551] Wed, 27 April 2005 09:32 Go to previous message
Joe Shultz is currently offline Joe Shultz
Messages: 3
Registered: July 2009
Junior Member
Ed,

You're a genius, adding options.put(XMLResource.OPTION_EXTENDED_META_DATA,
Boolean.TRUE); during a save along with the changes to the ecore solved my
problem

Thank you!



"Ed Merks" wrote:
Joe,

What are you using to build your model? You really should set these
annotations so that they are in the .ecore before you generated so that they
will already be there in the generated EPackage. They can even be
expressed in the @model annotations. If you add them to your .ecore file
and generate the Java, you'll see that these annotations are generated into
your Java source.

What I failed to tell you (stupid me not stupid you) is that in order for
these annotations to be respected, you have to use
XMLResource.OPTION_EXTENDED_META_DATA as an option during save.


Joe Shultz wrote:
Ed,

Sorry for being dumb but I need some more help. I've tried setting the
feature kind in a number of ways and it keeps getting serialized as an
Attribute rather than an Element. First, I tried adding the following calls
to the XMLHelper() method I described previously:

emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitialization
().eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().eC
ontainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);
emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization()
..eContainingFeature(), ExtendedMetaData.ELEMENT_FEATURE);

but this had no effect. I then searched the newsgroup and found a series of
posts between you and Nima Mazloumi (from Oct 2004). You suggested editing
the ecore file directly, so I tried that:

<eStructuralFeatures xsi:type="ecore:EAttribute"
name="narrowbandInitialization"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
</eAnnotations>
</eStructuralFeatures>

However, it was still serialized as an attribute after re-generating all in
My.genmodel. Can you go into a little more detail in how and where I should
set the feature kind? I am not using Omondo or Rose to help with the
modeling, but at this point I'm willing to try anything.

Thanks for your time,
- Joe


Ed Merks wrote:

Joe,

If it's serialized as an XML attribute, you can't (as far as I know)
prevent the XML parser from collapsing the white space. You'll need to
serialize it as an element, which you can do by setting the feature kind
to be ELEMENT_FEATURE.


Joe Shultz wrote:


Hello,



I have created an EMF model, and among other things, I've added a few
EAttributes of type EString. I am using this EString to hold text that is
formatted with whitespace (spaces, tabs, cartridge returns). When the

model

is persisted via XML and then re-opened, all of the whitespace characters
are converted into a single space, so I am losing all my formatting.



I've tried (without success) to set extended metadata options to preserve
this whitespace. I created a ResourceImpl and tried to override the
createXMLHelper() method to add support for preserving whitespace:



public class DesignResourceImpl extends XMIResourceImpl {
protected XMLHelper createXMLHelper() {
XMLHelper h = super.createXMLHelper();
ExtendedMetaData emd = h.getExtendedMetaData();
if (emd == null)
{
emd = new BasicExtendedMetaData();
}


emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndInitializatio

n

().eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);


emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndExecution().e

C

ontainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);


emd.setFeatureKind(DesignPackage.eINSTANCE.getChain_Narrowba ndFinalization(

)

..eContainingFeature(), ExtendedMetaData.PRESERVE_WHITE_SPACE);
h.setExtendedMetaData(emd);
return h;
}

....

}



This doesn't seem to have any effect. Does anyone know the proper way to
preserve this formatted text?



Thanks!

- Joe
Previous Topic:Contain[er|ment] in EMF FeatureMap?
Next Topic:EMap attribute problem
Goto Forum:
  


Current Time: Sat May 25 21:33:34 EDT 2013

Powered by FUDForum. Page generated in 0.01878 seconds