[英]Why Eclipse give me an error when I insert this XML Soap request inside a String?
I am pretty new in SOAP web services in Java and I have the following problem. 我在Java的SOAP Web服务中还很陌生,并且遇到以下问题。
I have a method that create the SOAP Envelop for a REQUEST , this one: 我有一个方法可以为REQUEST创建SOAP信封 :
String soapXml = "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soapenv:Header/><soapenv:Body><tem:getConfigSettings><tem:login>name.surname</tem:login><tem:password>myPassword</tem:password><tem:ipAddress>192.120.30.40</tem:ipAddress><tem:clientVersion>1</tem:clientVersion><tem:lastUpdateTime>1</tem:lastUpdateTime></tem:getConfigSettings></soapenv:Body></soapenv:Envelope>";
As you can see I put the SOAP REQUEST Envelop inside the soapXml string. 如您所见,我将SOAP REQUEST Envelop放入soapXml字符串中。
The problem is that when I put this XML inside this String object Eclipse marks this line as incorrect saying me the following error: 问题是,当我将XML放入此String对象时,Eclipse将此行标记为不正确,并向我显示以下错误:
Multiple markers at this line
- Syntax error, insert ";" to complete Statement
- Line breakpoint:WebServiceHelper [line: 124] - authentication(String, String, String,
String)
Is it an error concerning how I have inserted the XML code inside a String? 关于如何将XML代码插入字符串中是否出错? Or what? 要不然是啥? What can I do to solve? 我该怎么办?
Tnx TNX
Andrea 安德里亚
The string you are inserting contains "
, terminating the initial string. 您要插入的字符串包含"
,以终止初始字符串。
Escape every "
as \\"
inside your SOAP string. 转义SOAP字符串中的每个"
as \\"
。
WRONG:
String soapXml = "<soapenv:Envelope xmlns:soapenv="http://sc ... to be continued
CORRECT:
String soapXml = "<soapenv:Envelope xmlns:soapenv=\"http://sc ... to be continued
You need to escape the "
inside the strings like this \\"
您需要转义"
像这样的字符串内的\\"
String soapXml = "<soapenv:Envelope xmlns:"+
"soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""+
"xmlns:tem=\"http://tempuri.org/\"><soapenv:Header/><soapenv:Body>"+
"<tem:getConfigSettings><tem:login>name.surname</tem:login>"+
"<tem:password>myPassword</tem:password><tem:ipAddress>192.120.30.40"+
"</tem:ipAddress><tem:clientVersion>1</tem:clientVersion>"+
"<tem:lastUpdateTime>1</tem:lastUpdateTime></tem:getConfigSettings>"+
"</soapenv:Body></soapenv:Envelope>";
More suitable example would be 更合适的例子是
String s = "hello";
String s2 = "\"hello\"";
System.out.println(s); => hello
System.out.println(s2); => "hello"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.