1

I am working on an automation script that uses SoapUI api classes to read a wsdl and execute it after dynamically filling data from a excel file.

I am using XmlHolder class to get or set Soap request Node values but I am facing issues in accessing the request XML nodes using the XPath with XmlHolder. Following is the sample request and the code that I have tried:

//sample Soap request

<soapenv:Envelope     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
       <soapenv:Header/>
       <soapenv:Body>
          <web:ConversionRate>
             <web:FromCurrency>?</web:FromCurrency>
             <web:ToCurrency>?</web:ToCurrency>
          </web:ConversionRate>
       </soapenv:Body>
    </soapenv:Envelope>

      //code
     XmlHolder xmlHolder = null;
     try {
        xmlHolder = new XmlHolder(soapOperation.createRequest(true));
        } catch (XmlException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        };

        xmlHolder.declareNamespace("web","http://www.webserviceX.NET");

        // Here tagCell.getStringCellValue() = FromCurrency

        System.out.println("FromCurrency= " + request.getNodeValue(".//web:" + tagCell.getStringCellValue()));
        request.setNodeValue(".//web:" + tagCell.getStringCellValue() , valCell.getStringCellValue());

        //Other tried xPath
        //System.out.println("FromCurrency= " + request.getNodeValue("//web:" + tagCell.getStringCellValue()));
        //System.out.println("FromCurrency= " + request.getNodeValue("//:" + tagCell.getStringCellValue()));
        //System.out.println("FromCurrency= " + request.getNodeValue("//*:" + tagCell.getStringCellValue()));

Can anyone please suggest the xPath for XmlHolder.setNodeValue().

Also to be noted here that Soap nodes have namespace i.e; <web:FromCurrency>

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rupendra
  • 608
  • 2
  • 11
  • 42

1 Answers1

0

My bad. It was a problem of a missing jar.

Also there is no need of specifying any namespace with XmlHolder.

Now the working code is:

//code

XmlHolder xmlHolder = null;
 try {
    xmlHolder = new XmlHolder(soapOperation.createRequest(true));
    } catch (XmlException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    };

    // Here tagCell.getStringCellValue() = FromCurrency

    System.out.println("FromCurrency= " + request.getNodeValue("//*:" + tagCell.getStringCellValue()));
    request.setNodeValue("//*:" + tagCell.getStringCellValue() , valCell.getStringCellValue());

Enjoy

Rupendra
  • 608
  • 2
  • 11
  • 42
  • Question was setting node value using `xpath`. But it is answered saying missing jar file. There is no connection between Q & A. – Rao Aug 06 '16 at 06:12
  • @Rao, I think you did not read the full answer, I have provided details about using the correct xPath way also to access the node values without adding even a namespace for the SOAP request/Response . Anyways, I don't blame you. Some people feed on others left junk. Thanks for this beautiful comment. – Rupendra Aug 08 '16 at 01:07
  • 1
    Thanks @Rupendra, your answer helped me resolving similar problem. – error_handler Oct 17 '16 at 09:15