Forum Discussion
PaulDonny
12 years agoRegular Contributor
Christian, this is something I often considered and pondered as well. The reasoning, I believe, is that if SoapUI displays the values as null it will just have the XML as <ns1:example/> all across the testStep. If you want to change them to null, or a default property, just manually edit them or parse them using groovy prior to passing them.
I have posted Java code on the forum elsewhere that does handle this and it should work within groovy to be able to handle what you need. However, my Java uses things like hashMaps where you will have to edit the code and have it use a property or DataSink within SoapUI. Here is some sample code.
What this code does is 2 things:
1) Uses a "loopers" map to change the XML where multiple are allowed. It's rather barbaric in the way it handles it since that function was a test function that I no longer use.
2) Uses a properties map to grab the information from and insert into the XML based on the name of the XML tag. I am now using an XPath based system, I would suggest you do the same.
I have posted Java code on the forum elsewhere that does handle this and it should work within groovy to be able to handle what you need. However, my Java uses things like hashMaps where you will have to edit the code and have it use a property or DataSink within SoapUI. Here is some sample code.
NodeList nodes = XmlUtils.parseXml(operation.getRequestAt(0).getRequestContent()).getChildNodes();
parseNodes(nodes,operation.getName());
static void parseNodes(NodeList nodeList, String testName) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getLocalName() != null && !childNode.getLocalName().equals("null") && config.containsKey(testName.toLowerCase())) {
if (loopers.containsKey(childNode.getLocalName().toLowerCase())) {
System.out.println(loopers.get(childNode.getLocalName().toLowerCase()));
for (int j = 0; j<Integer.parseInt(loopers.get(childNode.getLocalName().toLowerCase())); j++) {
Node clone = childNode.cloneNode(true);
childNode.getParentNode().insertBefore(clone,childNode);
}
childNode.getParentNode().removeChild(childNode);
loopers.remove(childNode.getLocalName().toLowerCase());
}
}
NodeList children = childNode.getChildNodes();
if (children != null) {
parseNodes(children, testName);
}
}
}
What this code does is 2 things:
1) Uses a "loopers" map to change the XML where multiple are allowed. It's rather barbaric in the way it handles it since that function was a test function that I no longer use.
2) Uses a properties map to grab the information from and insert into the XML based on the name of the XML tag. I am now using an XPath based system, I would suggest you do the same.