Forum Discussion

bgerhards's avatar
bgerhards
Occasional Contributor
11 years ago

[Resolved] Replace All "?"

Good morning,

In our shop, we use web services for mainframe interaction. We create new requests via SoapUI on a daily basis. Upon creation of a request, every node is populated with a question mark (?). In order for our request to go through successfully, we sometimes need to remove the questions marks, but as a good practice, we need to remove all question marks. For us to easily remove every one of them (sometimes hundreds of nodes), we copy the request into Notepad++ and find/replace having the question mark in the find and nothing, not even a space, in the replace. SoapUI does not allow for nothing to be in the Replace With field. With no error, it does nothing. This would be a convenience for users to be allowed to find/replace all question marks without a hassle. Maybe a menu feature to clear all nodes, that would be great as well.

Am I missing a feature to remove all question marks upon creation of a project/request? If so, please direct me accordingly.

3 Replies

  • SiKing's avatar
    SiKing
    Community Expert
    could you just replace all occurrences of [tt:3m76nusq]>?<[/tt:3m76nusq] with [tt:3m76nusq]><[/tt:3m76nusq]
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Here is a snippet of groovy that will replace every value in all test requests as null. Put in the logic to replace it with your specific requests and your golden.



    //Some Java imports in order to handle things a bit better
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    def XmlUtils = com.eviware.soapui.support.xml.XmlUtils;
    def XML = "";
    //Looping through all WsdlTestRequestStep type of Steps
    for ( tests in testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class) ) {
    //Setting up a NodeList for all of the nodes within the request
    NodeList nodes = XmlUtils.parseXml(tests.getPropertyValue("Request")).getChildNodes();
    //Calling the parseNodes function
    parseNodes(nodes);
    //Switching the nodes back to a string
    XML = XmlUtils.prettyPrintXml(XmlUtils.createXmlObject(nodes.item(0).getParentNode()));
    //Setting the string to the Request Property
    tests.setPropertyValue("Request",XML);
    }

    static void parseNodes(NodeList nodeList) {
    //Loops through the nodeList
    for (int i = 0; i < nodeList.getLength(); i++) {
    //Get the current node
    Node childNode = nodeList.item(i);
    //Set the node value to Null (THIS IS WHERE YOU WOULD START TO ADD IN YOUR LOGIC OR WITH A DIFFERENT STEP
    //If you just want this as a post processing parser than do an if statement to check if the value is ?
    com.eviware.soapui.support.xml.XmlUtils.setNodeValue(childNode,null);
    //Check if it has any child nodes
    NodeList children = childNode.getChildNodes();
    if (children != null) {
    //If it does have child nodes, redo this function
    parseNodes(children);
    }
    }
    }