如何在web服务中将XML转换为字符串并将其传递给java代码?
嗨,我已经试了一段时间了。。我想在Java类中解析XML。但要解析XML,我需要将其传递给java类。我该怎么做? 这是在LISA中测试的一段代码如何在web服务中将XML转换为字符串并将其传递给java代码?,java,xml,web-services,soap,Java,Xml,Web Services,Soap,嗨,我已经试了一段时间了。。我想在Java类中解析XML。但要解析XML,我需要将其传递给java类。我该怎么做? 这是在LISA中测试的一段代码 3. 22 它当前在本地主机上运行,从该主机将值传递到java jar,并显示获得的结果。相同的匹配脚本是 导入计算添加//这是要导入以添加的java包 字符串操作名=null; String operationname=incomingRequest.getOperation()//传入请求引用上述xml 字符串i=incomingReques
3.
22
它当前在本地主机上运行,从该主机将值传递到java jar,并显示获得的结果。相同的匹配脚本是
导入计算添加//这是要导入以添加的java包
字符串操作名=null;
String operationname=incomingRequest.getOperation()//传入请求引用上述xml
字符串i=incomingRequest.getArguments().get(“firstnumber”);
字符串j=incomingRequest.getArguments().get(“secondnumber”);
int ifirstNumber=Integer.parseInt(i);
int jsecondNumber=Integer.parseInt(j);
加法myobj=新加法(ifirstNumber,jsecondNumber)//值被传递给类的构造函数
int Result=myobj.giveResult()//函数giveResult返回总和
字符串sResponseXML=“”;
sResponseXML=
“\n”+
“\n”+
“\n”+
“+Result+”\n”+
“
\n”+
“\n”+
"";
//为属性RESPONSE\u XML赋值
testExec.setStateValue(“RESPONSE_XML”,sResponseXML);
这是成功执行的正确代码。但是现在我想以字符串的形式将上面的整个XML文件传递给JavaJAR。请帮忙
现在您将xml的内容设置为字符串。您已经在代码段中以字符串形式传递xml,因此我不知道您的确切问题是什么?我的问题是,我是通过web服务来完成这项工作的。。xml代码并不是直接调用Java类。。它必须通过虚拟服务环境。。。
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<addnumber xmlns="http://ejb3.examples.itko.com/">
<firstnumber xmlns="">3</firstnumber>
<secondnumber xmlns="">22</secondnumber>
</addnumber>
</soapenv:Body>
</soapenv:Envelope>
import Calc.Addition; //this the java package to import for addition
String operationname = null;
String operationname = incomingRequest.getOperation(); //incoming request refers to the above xml
String i = incomingRequest.getArguments().get("firstnumber");
String j = incomingRequest.getArguments().get("secondnumber");
int ifirstNumber = Integer.parseInt (i);
int jsecondNumber = Integer.parseInt (j);
Addition myobj = new Addition(ifirstNumber,jsecondNumber ); //values are passed to the constructor of class
int Result = myobj.giveResult(); //function giveResult gives back the sum
String sResponseXML = "";
sResponseXML =
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" >\n"+
"<soap:Body> \n"+
"<p xsi:type=\"p:ServiceMessageObject\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema- instance\" xmlns:api=\"http://api.webservices.cc.guidewire.com/\" xmlns:util=\"http://UtilLibrary\" xmlns:xa=\"http://XactimateMediationLibrary\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n"+
"<AdditionResult>"+ Result +"</AdditionResult>\n"+
"</p>\n"+
"</soap:Body>\n"+
"</soap:Envelope>";
// Assigning value to the property RESPONSE_XML
testExec.setStateValue("RESPONSE_XML",sResponseXML );
import java.io.*;
public class Check
{
public static void main(String [] args)
{
BufferedReader br = null;
try {
br= new BufferedReader(new FileReader(Fname));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String xmlinput;
StringBuffer sb= new StringBuffer();
try {
while((xmlinput=br.readLine()) !=null)
{
sb.append(xmlinput.trim());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(sb.toString());
}
}