I am trying to write up some code in Mirth Connect that takes an XML tag and removes all attributes from inside of it.
Example:
<code nullFlavor="UNK" xsi:type="CD">
Desired result:
<code/>
I could do something like this:
delete msg['code']['@nullFlavor']
delete msg['code']['@xsi:type']
But I ideally want to handle ALL possible values that could come in, not just nullFlavor and xsi:type. Is there a way to do this?
I am trying to write up some code in Mirth Connect that takes an XML tag and removes all attributes from inside of it.
Example:
<code nullFlavor="UNK" xsi:type="CD">
Desired result:
<code/>
I could do something like this:
delete msg['code']['@nullFlavor']
delete msg['code']['@xsi:type']
But I ideally want to handle ALL possible values that could come in, not just nullFlavor and xsi:type. Is there a way to do this?
Share Improve this question asked Mar 27 at 2:48 Johnny TJohnny T 193 bronze badges 1- 2 Can't you replace the tag with a new tag that has no attributes? – Tim Roberts Commented Mar 27 at 2:54
1 Answer
Reset to default 0It can be achieved by running the following script-
// Get the <code> element
var myElement = msg['code'];
// Check if the element exists
if (myElement) {
// Loop through all attributes and remove them
for each (var attr in myElement.@*) {
delete myElement['@' + attr.name()];
}
}
// Return the modified message
msg;