使用Java 1.8中的XmlHolder在运行时设置SOAP请求节点值

时间:2016-08-05 08:38:05

标签: java xpath soap xml-parsing soapui

我正在研究一个自动化脚本,该脚本使用SoapUI api类来读取wsdl并在从excel文件中动态填充数据后执行它。

我正在使用XmlHolder类来获取或设置Soap请求节点值,但是我在使用XPath with XmlHolder访问请求XML节点时遇到了问题。 以下是示例请求和我尝试过的代码:

//示例肥皂请求

private FrameworkElement originalSource;
private void ChoiceA_Click(object sender, RoutedEventArgs e)
{
    var itemdatacontext = originalSource.DataContext;
}

private void ListView_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
    originalSource = (FrameworkElement)e.OriginalSource;
}

任何人都可以为XmlHolder.setNodeValue()建议xPath。

此处还要注意,Soap节点具有名称空间,即; <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()));

提前致谢

1 个答案:

答案 0 :(得分:0)

我的坏。这是一个缺少罐子的问题。

此外,无需使用XmlHolder指定任何名称空间。

现在工作代码是:

//代码

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());

享受