Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Is there a way to use a string as raw XML?
Is there a way to use a string as raw XML? [message #1234430] Wed, 22 January 2014 00:17 Go to next message
Dan Kaplan is currently offline Dan KaplanFriend
Messages: 13
Registered: May 2010
Junior Member
Forgive me because I know very little about EMF. I'm using a library named MDHT and am having an issue with it. This library has a class named org.openhealthtools.mdht.uml.cda.StrucDocText. That interface extends org.eclipse.emf.ecore.EObject. The StrucDocText has an addText method on it that takes a String.

My issue is that when org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#saveElementFeatureMap is called, it escapes the text I'm adding in addText. Instead of escaping this String, I'd like it to save this String (but not others) as-is. When I look at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#saveElementFeatureMap I don't see a path I can go down that gives me this option:

There's a switch for if (entryFeature == XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT). This looks like the right fit, but that escapes if an org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.Escape is provided. Is there an entryFeature I can give this to mean, "just use this String value without modification"?

MDHT already lets me do this but in an unacceptably inefficient way. Here's how it works:

			Resource.Factory factory = new GenericXMLResourceFactoryImpl();
			XMLResource resource = (XMLResource) factory.createResource(null);
			resource.load(new URIConverter.ReadableInputStream("<text>" + xmlString + "</text>"), null);
			XMLTypeDocumentRoot root = (XMLTypeDocumentRoot) resource.getContents().get(0);
			AnyType value = (AnyType) root.getMixed().getValue(0);
			text = CDAFactory.eINSTANCE.createStrucDocText();
			text.getMixed().addAll(value.getMixed());



But I've already constructed this xmlString value as XML before I called addText. There is a serious performance hit to calling resource.load and text.getMixed().addAll. I need to avoid both if possible.
Re: Is there a way to use a string as raw XML? [message #1240929 is a reply to message #1234430] Fri, 07 February 2014 08:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Dan,

Comments below.

On 22/01/2014 1:17 AM, Dan Kaplan wrote:
> Forgive me because I know very little about EMF. I'm using a library
> named MDHT and am having an issue with it. This library has a class
> named org.openhealthtools.mdht.uml.cda.StrucDocText. That interface
> extends org.eclipse.emf.ecore.EObject. The StrucDocText has an
> addText method on it that takes a String.
> My issue is that when
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#saveElementFeatureMap is
> called, it escapes the text I'm adding in addText. Instead of
> escaping this String, I'd like it to save this String (but not others)
> as-is.
It only escapes what needs to be escaped to produce well-formed XML, so
it's not clear what you're trying to produce...
> When I look at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl#saveElementFeatureMap I
> don't see a path I can go down that gives me this option:
>
> There's a switch for if (entryFeature ==
> XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT). This looks
> like the right fit, but that escapes if an
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.Escape is provided. Is
> there an entryFeature I can give this to mean, "just use this String
> value without modification"?
>
> MDHT already lets me do this but in an unacceptably inefficient way.
> Here's how it works:
>
> Resource.Factory factory = new
> GenericXMLResourceFactoryImpl();
> XMLResource resource = (XMLResource)
> factory.createResource(null);
> resource.load(new
> URIConverter.ReadableInputStream("<text>" + xmlString + "</text>"),
> null);
> XMLTypeDocumentRoot root = (XMLTypeDocumentRoot)
> resource.getContents().get(0);
> AnyType value = (AnyType) root.getMixed().getValue(0);
> text = CDAFactory.eINSTANCE.createStrucDocText();
> text.getMixed().addAll(value.getMixed());
>
>
> But I've already constructed this xmlString value as XML before I
> called addText. There is a serious performance hit to calling
> resource.load and text.getMixed().addAll. I need to avoid both if
> possible.
It sounds like you're trying to add as test content, a string that you
really want to be actual embedded XML tags... That's only possible if
the model itself allows that, but given I know nothing about
StrucDocText I can't say if it supports that. This article is likely
useful for understanding how that would be possible:

http://www.theserverside.com/news/1364302/Binding-XML-to-Java


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Is there a way to use a string as raw XML? [message #1354604 is a reply to message #1240929] Wed, 14 May 2014 10:32 Go to previous messageGo to next message
Mathieu Fossay is currently offline Mathieu FossayFriend
Messages: 1
Registered: May 2014
Junior Member
Hi Dan,
Have you finally solve your problem?
I have the same issue:
I have to generate a org.openhealthtools.mdht.uml.cda.ccd.ContinuityOfCareDocument object, and all works fine except the html text part storage.
Like you, I had to fill a section with an html representation in the tag "<text>" of this content's section.
And like you, the engine escape all the html tags presents in the String content added by the StrucDocText.addText method.
Have you fix this issue in a simple way? and how?

Thanks,
Mathieu.
Re: Is there a way to use a string as raw XML? [message #1355300 is a reply to message #1354604] Wed, 14 May 2014 17:12 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mathieu,

Comments below.

On 14/05/2014 3:19 PM, Mathieu Fossay wrote:
> Hi Dan,
> Have you finally solve your problem?
> I have the same issue:
> I have to generate a
> org.openhealthtools.mdht.uml.cda.ccd.ContinuityOfCareDocument object,
> and all works fine except the html text part storage.
How is that modeled?
> Like you, I had to fill a section with an html representation in the
> tag "<text>" of this content's section.
What's a "section"?
> And like you, the engine escape all the html tags presents in the
> String content added by the StrucDocText.addText method.
You need to create structured content if you want the structure serialized.
> Have you fix this issue in a simple way? and how?
Did you read the article I referenced?
>
> Thanks,
> Mathieu.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF - Question about EMF code generation
Next Topic:[GWT] Could not initialize class org.eclipse.emf.server.ecore.resource.URIServiceImpl
Goto Forum:
  


Current Time: Thu Apr 25 01:54:25 GMT 2024

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

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

Back to the top