web stats
Mirth Community - View Single Post - Mirth Tools: User defined functions
View Single Post
Old 03-29-2013, 09:56 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default Strip Empty Nodes from XML

UPDATE: I've created a public GitHub repository to track these example channels, code templates, scripts, or whatever else!


To start with I only added the ones I wrote, because I didn't want to presume and add code from others without their explicit permission. Pull requests welcome!
stripEmptyNodes: Recursively iterates through all descendant nodes of an E4X XML object and removes those that are empty (or those whose children are all empty).

  • node: The node to iterate through. If node itself is empty, it will not be removed from its parent.

  • Get rid of all empty nodes in the inbound XML structure (msg):

The code:

function stripEmptyNodes(node) {
	var name = '', index = -1;
	for each (child in node.children()) {
		index = (name != child.name() ? 0 : index+1);
		name = child.name();
		if (!child.toString())
			delete node[child.name()][index];
Attached Files
File Type: xml stripEmptyNodes.xml (678 Bytes, 154 views)
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

- How do I foo?
- You just bar.

Last edited by narupley; 06-08-2018 at 10:35 AM.
Reply With Quote