1
我正在使用SoapUI api類讀取wsdl並在從excel文件動態填充數據後執行它。設置SOAP請求使用Java 1.8中的XmlHolder在運行時節點值
我正在使用XmlHolder類來獲取或設置Soap請求節點值,但我在使用XPath與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.setNodeValue中的XPath()。
這裏還要指出,肥皂節點有命名空間,即; <web:FromCurrency>
在此先感謝
問題是使用'xpath'設置節點值。但它回答說缺少jar文件。在問與答之間沒有任何聯繫。 – Rao
@Rao,我想你沒有閱讀完整的答案,我已經提供了有關使用正確xPath方法的詳細信息以訪問節點值而不添加SOAP請求/響應的命名空間。無論如何,我不怪你。有些人吃剩下的垃圾。感謝這個美麗的評論。 – Riky
謝謝@Rupendra,你的回答幫助我解決了類似的問題。 –