web stats
Outbound message template generates unwanted nodes or access is always undefined - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2018, 03:34 PM
ppazos ppazos is offline
OBX.2 Kenobi
 
Join Date: May 2008
Posts: 63
ppazos
Default Outbound message template generates unwanted nodes or access is always undefined

I have a channel that receives JSON and converts that to XML, following this configuration:

JSON -> source connector -> XML / XML -> destination connector -> XML

In the source connector transformer, I set a JSON message template for the inbound, and an XML message template for the outbound. For that one I removed the "strip namespace" because was causing the whole channel to fail, since the XML uses xsi:type.

This is a simplified XML with some extra dummy nodes for testing:

<versions xmlns="http://schemas.openehr.org/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<coco>pepe</coco>
<pupu><popo>ucul</popo></pupu>
<version xsi:type="ORIGINAL_VERSION">
<contribution>
<id xsi:type="HIER_OBJECT_ID">
<value>0443fb97-7955-47a5-a414-8ba2e4454a5e</value>
</id>
<namespace>EHR::COMMON</namespace>
<type>CONTRIBUTION</type>
</contribution>
</version>
</versions>


Then in the JS transformer, I try to set a value like: tmp['coco'] = "moflete";


And this is the XML that is being generated, not instead of setting the value for the existing "coco" node, it generated a new node with empty namepsace:

<versions xmlns="http://schemas.openehr.org/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<coco>pepe</coco>
<pupu>
<popo>ucul</popo>
</pupu>
<version xsi:type="ORIGINAL_VERSION">
<contribution>
<id xsi:type="HIER_OBJECT_ID">
<value>0443fb97-7955-47a5-a414-8ba2e4454a5e</value>
</id>
<namespace>EHR::COMMON</namespace>
<type>CONTRIBUTION</type>
</contribution>
</version>
<coco xmlns="">moflete</coco>
</versions>


If I try to set other nodes, accessing indexes for nodes with multiple occurrences, I get "can't get index 0 on undefined", or if I try to tmp[x][y].copy() I get "cant call copy on undefined", when x.y is a valid element in my outbound XML message.

Not sure what is going on, I suspect this has to do with some problem handling the namespaces correctly.

I need to maintain the namespaces declared when processing through mirth since the final message should have them.

I'm working with Mirth 3.5.2.
Reply With Quote
  #2  
Old 07-13-2018, 08:07 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 470
agermano is on a distinguished road
Default

Option 1 - explicit namespace
Code:
var ns = new Namespace('http://schemas.openehr.org/v1');
tmp.ns::['coco'] = "moflete";
// or tmp.ns::coco = "moflete";
Option 2 - default namespace
Code:
default xml namespace = 'http://schemas.openehr.org/v1';
tmp['coco'] = "moflete";
Option 3 - wildcard namespace
This will create a new element with the default namespace if the element is not found (the same thing you saw in your example.) The default namespace is normally empty unless you set it.
Code:
tmp.*::['coco'] = "moflete";

Last edited by agermano; 07-13-2018 at 08:13 AM.
Reply With Quote
  #3  
Old 08-10-2018, 01:21 PM
ppazos ppazos is offline
OBX.2 Kenobi
 
Join Date: May 2008
Posts: 63
ppazos
Default

Thanks, I started to use the wildcard namespace.

But is a little annoying to use that everywhere when there is only one namespace for the whole document. I would love if this extra complexity can be handled internally so we don't need to add namespaces everywhere.
Reply With Quote
Reply

Tags
error, namespaces, outbound, xml

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 02:38 PM.


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