Announcement

Collapse
No announcement yet.

Outbound message template generates unwanted nodes or access is always undefined

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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, 08:13 AM.

    Comment


    • #3
      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.

      Comment

      Working...
      X