web stats
Mirth Community - View Single Post - Assigning Arbitrary Empty XML Node
View Single Post
Old 04-30-2019, 02:18 PM
ace ace is offline
Mirth Newb
Join Date: May 2016
Location: Austin, TX, USA
Posts: 8
ace is on a distinguished road
Default Assigning Arbitrary Empty XML Node

Thanks for the ideas, agermano. I am just getting back to this.

This approach is the most useful for me. My previous report that it did not work was the result of a bad test. User error. / My Bad.:

var msgXML = new XML(SerializerFactory.getSerializer('HL7V2').toXML (connectorMessage.getRawData().toString()));
var segment = 'PID';
var hl7FieldName = 'PID.7';
msgXML[segment][hl7FieldName] = <{hl7FieldName}/>;
var neutralizedMessage = SerializerFactory.getSerializer('HL7V2').fromXML(m sgXML.toString());//THE SPACE BETWEEN m AND s IS ACTUALLY NOT THERE!!!

But for replacing an arbitrarily deep field, all but the 3rd one, require me to access the Array of Arrays with hard-coded depths of reference, for example, where msgXML[segName][fieldName] is 2 levels deep. Since I want to write a function that can take an arbitrary field or subfield name, I can imagine parsing the field name and using the 3rd approach to build a copy of the msgXML Array, one field at a time, in a series of loops, and then convert that edited copy back to XML, but that seems clunky, and probably slow-performing, so I was hoping there was a way to build a string that could be used as a path into the array (or into the XML) that could be used as an index for the edit.

Last edited by ace; 05-02-2019 at 07:18 AM. Reason: Removing bad test results. :-P
Reply With Quote