summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhishek Shekhar <abhishek.shekhar1@amdocs.com>2018-01-08 21:26:29 +0530
committerAbhishek Shekhar <abhishek.shekhar1@amdocs.com>2018-01-08 21:27:43 +0530
commitd4c74a6c9eb614fd8820606c81be39f65d7e5363 (patch)
tree4819a99e6e69e92856aa24e68510b972f9433f10
parent30585fe9fa4c810c1f0589010f53221a588a31c7 (diff)
Utility Methods: clean xml of all empty nodes
Change-Id: I29e26659da6d031237dffe940373515ccaa645c8 Issue-ID: SO-377 Signed-off-by: Abhishek Shekhar <abhishek.shekhar1@amdocs.com>
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtils.groovy27
1 files changed, 27 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtils.groovy
index 06992455a2..719aeb837f 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtils.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtils.groovy
@@ -986,4 +986,31 @@ class MsoUtils {
return requestId
}
+
+ /**
+ * Remove all the empty nodes and attributes from the within the given node
+ * @param node
+ * @return true if all empty nodes and attributes were removed.
+ */
+ public boolean cleanNode( Node node ) {
+ node.attributes().with { a ->
+ a.findAll { !it.value }.each { a.remove( it.key ) }
+ }
+ node.children().with { kids ->
+ kids.findAll { it instanceof Node ? !cleanNode( it ) : false }
+ .each { kids.remove( it ) }
+ }
+ node.attributes() || node.children() || node.text()
+ }
+
+ /**
+ *
+ * @param xml
+ * @return String representation of xml after removing the empty nodes and attributes
+ */
+ public String cleanNode(String xmlString) {
+ def xml = new XmlParser(false, false).parseText(xmlString)
+ cleanNode(xml)
+ return XmlUtil.serialize(xml)
+ }
}