web stats
Replacing tag names with their semantinc description ERROR - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 10-14-2019, 05:29 AM
oshimada oshimada is offline
What's HL7?
Join Date: Jun 2019
Posts: 4
oshimada is on a distinguished road
Default Replacing tag names with their semantinc description ERROR

I'm getting this error
Transformer error
ERROR MESSAGE: Error evaluating transformer
org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
at org.apache.xerces.dom.CoreDocumentImpl.checkQName( Unknown Source)
at org.apache.xerces.dom.ElementNSImpl.setName(Unknow n Source)
at org.apache.xerces.dom.ElementNSImpl.rename(Unknown Source)
at org.apache.xerces.dom.CoreDocumentImpl.renameNode( Unknown Source)
at org.mozilla.javascript.xmlimpl.XmlNode.renameNode( XmlNode.java:386)
at org.mozilla.javascript.xmlimpl.XML.setName(XML.jav a:633)
at org.mozilla.javascript.xmlimpl.XMLObjectImpl.execI dCall(XMLObjectImpl.java:724)
at org.mozilla.javascript.IdFunctionObject.call(IdFun ctionObject.java:101)
at org.mozilla.javascript.xmlimpl.XMLList.call(XMLLis t.java:786)
at org.mozilla.javascript.Interpreter.interpretLoop(I nterpreter.java:1479)
at org.mozilla.javascript.Interpreter.interpret(Inter preter.java:815)
at org.mozilla.javascript.InterpretedFunction.call(In terpretedFunction.java:109)
at org.mozilla.javascript.ContextFactory.doTopCall(Co ntextFactory.java:405)
at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr iptRuntime.java:3508)
at org.mozilla.javascript.InterpretedFunction.exec(In terpretedFunction.java:120)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.executeScript(JavaScriptTask.java:150)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:143)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

with the following code in the transformer
String.prototype.escape = function() {return (this+'').replace(/[\s\/<>',]/g,'')};

for each (seg in msg.children()) {
	if (seg.name()) {
		seg.setName(Component.getSegmentDescription(seg.name().toString()).escape() || seg.name());
	for each (field in seg.children()) {
		if (field.name()) {
			field.setName(Component.getSegmentorCompositeFieldDescription(field.name().toString(),false).escape() || field.name());

		for each (component in field.children()) {
			if (component.name()) {
				component.setName(Component.getCompositeFieldDescriptionWithSegment(component.name().toString(),false).escape() || 'Value');
return msg;
The intention from this code is to change the name of the xml namespaces with their full name , thing is in some messages i'm getting this exception (the majority of the messages pass the code and are correctly changed)
Please i'm asking for help
Reply With Quote
Old 10-22-2019, 02:46 AM
oshimada oshimada is offline
What's HL7?
Join Date: Jun 2019
Posts: 4
oshimada is on a distinguished road
Default any solution?

Any help?
Reply With Quote
Old 10-22-2019, 11:47 AM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road

That's a pretty neat bit of code.

The message I tried was failing with the same error message because of a description containing parentheses, which aren't in your escape function. It seems to fail hard enough that you can't even mitigate it by putting a try/catch around the call to setName().

You can remove the return msg; from the end of your code. Returning in a transformer will cause any remaining transformer steps to skip. The return value is not used.

As an alternative you could set a description attribute rather than renaming the element. Then you won't need to worry about bad characters in the name. Something like this:

const Component = com.mirth.connect.model.hl7v2.Component;

var desc;
for each (var seg in msg.children()) {
	if (desc = Component.getSegmentDescription(seg.name().toString())) { seg.@desc = desc; }

	for each (var field in seg.children()) {
		if (desc = Component.getSegmentorCompositeFieldDescription(field.name().toString(),false)) { field.@desc = desc }

		if (field.hasSimpleContent()) continue;

		for each (var component in field.children()) {
			desc = Component.getCompositeFieldDescriptionWithSegment(component.name().toString(), false);
			if (desc) { component.@desc = desc }

Last edited by agermano; 10-22-2019 at 01:10 PM.
Reply With Quote
Old 10-23-2019, 02:39 AM
oshimada oshimada is offline
What's HL7?
Join Date: Jun 2019
Posts: 4
oshimada is on a distinguished road

Thank you for your answer , and based on your answer adding the parantheses to my script would avoid the break and fix the errors ,
String.prototype.escape = function() {return (this+'').replace(/[\s\/<>',]/g,'').replace('(','').replace(')','')};
that fix it though?
Reply With Quote

hl7, hl7 conversion, xml, xml child segments, xml content

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 01:23 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation