+\r
+ /**\r
+ * Remove all the empty nodes and attributes from the within the given node\r
+ * @param node\r
+ * @return true if all empty nodes and attributes were removed.\r
+ */\r
+ public boolean cleanNode( Node node ) {\r
+ node.attributes().with { a ->\r
+ a.findAll { !it.value }.each { a.remove( it.key ) }\r
+ }\r
+ node.children().with { kids ->\r
+ kids.findAll { it instanceof Node ? !cleanNode( it ) : false }\r
+ .each { kids.remove( it ) }\r
+ }\r
+ node.attributes() || node.children() || node.text()\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param xml\r
+ * @return String representation of xml after removing the empty nodes and attributes\r
+ */\r
+ public String cleanNode(String xmlString) {\r
+ def xml = new XmlParser(false, false).parseText(xmlString)\r
+ cleanNode(xml)\r
+ return XmlUtil.serialize(xml)\r
+ }\r