因为我们在test_suite.xml中定义了多个动作指令,比如<add_elements>,<update_elements>等,他们指示让我们Engine来对最终数据进行操作,这些动作指令不是数据,因此,他们并不包含在我们最终的数据结果集中,所以我们必须对他们进行移除。所以我们用以下代码来进行移除工作:
public class XMLManipulator {
public static String removeModifyConfFromXML(String xmlString) throws Exception{
Document doc = null;
doc = DocumentHelper.parseText(xmlString);
//remove the <add_elements> from the target xml
List<Node> addPart = doc.selectNodes("/test_suite/test_case/add_elements");
for(Node node: addPart){
node.getParent().remove(node);
}
//remove the <add_elements> from the target xml
List<Node> updatePart = doc.selectNodes("/test_suite/test_case/update_elements");
for(Node node: updatePart){
node.getParent().remove(node);
}
//remove the <remove_elements> from the target xml
List<Node> removePart = doc.selectNodes("/test_suite/test_case/remove_elements");
for(Node node: removePart){
node.getParent().remove(node);
}
//find document again
return doc.asXML();
}
..
}
这样最终的xml文件就不包含这些动作指令的代码片段了。