commit 9752c3399e6e1d947c9542f8801c0db24ca97f85
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Fri Jun 8 12:19:27 2012 +0200
NetTestParse: Remove XML comments before parsing
Comments in the XML recipe might interfere with the parser in some
cases and result in exceptions. The best way to deal with this is
to remove them from the recipe.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
Common/XmlPreprocessor.py | 15 +++++++++++++++
NetTest/NetTestParse.py | 2 ++
2 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/Common/XmlPreprocessor.py b/Common/XmlPreprocessor.py
index 88ae758..b20fec8 100644
--- a/Common/XmlPreprocessor.py
+++ b/Common/XmlPreprocessor.py
@@ -51,6 +51,21 @@ class XmlPreprocessor:
else:
raise XmlTemplateError("Alias name '%s' is reserved" %
name)
+ def remove_comments(self, node):
+ """
+ Remove all comment nodes from the tree.
+ """
+
+ comments = []
+ for child in node.childNodes:
+ if child.nodeType == node.COMMENT_NODE:
+ comments.append(child)
+ else:
+ self.remove_comments(child)
+
+ for comment in comments:
+ node.removeChild(comment)
+
def expand(self, node):
"""
Traverse DOM tree from `node' down and expand any
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index 5b5101a..68c0058 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -81,6 +81,8 @@ class NetTestParse:
dom = parseString(self._recipe_xml_string)
xml_prep = self._xml_prep
+ xml_prep.remove_comments(dom)
+
self._load_included_parts(dom)
dom_nettestrecipe = dom.getElementsByTagName("nettestrecipe")[0]
Show replies by date