Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java 1.8中使用XmlHolder在运行时设置SOAP请求节点值_Java_Xpath_Soap_Xml Parsing_Soapui - Fatal编程技术网

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

在Java 1.8中使用XmlHolder在运行时设置SOAP请求节点值,java,xpath,soap,xml-parsing,soapui,Java,Xpath,Soap,Xml Parsing,Soapui,我正在编写一个自动化脚本,该脚本使用SOAPUIAPI类读取wsdl,并在动态填充excel文件中的数据后执行它 我使用XmlHolder类获取或设置Soap请求节点值,但在使用XPath with XmlHolder访问请求XML节点时遇到了问题。 以下是我尝试过的示例请求和代码: //Soap请求示例 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="ht

我正在编写一个自动化脚本,该脚本使用SOAPUIAPI类读取wsdl,并在动态填充excel文件中的数据后执行它

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

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

?
?
//代码
XmlHolder=null;
试一试{
xmlHolder=newxmlholder(soapOperation.createRequest(true));
}捕获(XMLE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
};
declareNamespace(“web”http://www.webserviceX.NET");
//此处为tagCell.getStringCellValue()=FromCurrency
System.out.println(“FromCurrency=“+request.getNodeValue”(.//web:+tagCell.getStringCellValue());
request.setNodeValue(“.//web:+tagCell.getStringCellValue(),valCell.getStringCellValue());
//其他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());
有人能为XmlHolder.setNodeValue()推荐xPath吗

这里还需要注意的是,Soap节点具有名称空间,即<代码>


提前谢谢

我的错。这是一个罐子丢失的问题

此外,不需要使用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());

享受我的坏心情。这是一个罐子丢失的问题

此外,不需要使用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());

问题是使用xpath设置节点值。但答案是缺少jar文件。问与答之间没有联系。@Rao,我想您没有阅读完整的答案,我已经提供了有关使用正确的xPath方式访问节点值的详细信息,甚至没有为SOAP请求/响应添加名称空间。不管怎样,我不怪你。有些人吃别人留下的垃圾。感谢您的精彩评论。感谢@Rupendra,您的回答帮助我解决了类似的问题。问题是使用
xpath
设置节点值。但答案是缺少jar文件。问与答之间没有联系。@Rao,我想您没有阅读完整的答案,我已经提供了有关使用正确的xPath方式访问节点值的详细信息,甚至没有为SOAP请求/响应添加名称空间。不管怎样,我不怪你。有些人吃别人留下的垃圾。谢谢你的评论。谢谢@Rupendra,你的回答帮助我解决了类似的问题。