[Kimchi-devel] [PATCH] [Wok] Add function for removing XML element

Lucio Correia luciojhc at linux.vnet.ibm.com
Wed Jan 27 19:20:19 UTC 2016


Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 src/wok/xmlutils/utils.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/wok/xmlutils/utils.py b/src/wok/xmlutils/utils.py
index b75ca51..d02139c 100644
--- a/src/wok/xmlutils/utils.py
+++ b/src/wok/xmlutils/utils.py
@@ -1,7 +1,7 @@
 #
 # Project Wok
 #
-# Copyright IBM, Corp. 2014-2015
+# Copyright IBM, Corp. 2014-2016
 #
 # Code derived from Project Kimchi
 #
@@ -46,6 +46,17 @@ def xml_item_update(xml, xpath, value, attr=None):
     return ET.tostring(root, encoding="utf-8")
 
 
+def xml_item_remove(xml, xpath):
+    root = ET.fromstring(xml)
+
+    element = root.find(xpath)
+    parent = root.find(xpath + "/..")
+    if parent:
+        parent.remove(element)
+
+    return ET.tostring(root, encoding="utf-8")
+
+
 def dictize(xmlstr):
     root = objectify.fromstring(xmlstr)
     return {root.tag: _dictize(root)}
-- 
1.9.1




More information about the Kimchi-devel mailing list