[英]Why does eclipse give me errors when i try to run sample application?
[英]Why Eclipse give me an error when I insert this XML Soap request inside a String?
我在Java的SOAP Web服务中还很陌生,并且遇到以下问题。
我有一个方法可以为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>";
如您所见,我将SOAP REQUEST Envelop放入soapXml字符串中。
问题是,当我将XML放入此String对象时,Eclipse将此行标记为不正确,并向我显示以下错误:
Multiple markers at this line
- Syntax error, insert ";" to complete Statement
- Line breakpoint:WebServiceHelper [line: 124] - authentication(String, String, String,
String)
关于如何将XML代码插入字符串中是否出错? 要不然是啥? 我该怎么办?
TNX
安德里亚
您要插入的字符串包含"
,以终止初始字符串。
转义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
您需要转义"
像这样的字符串内的\\"
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>";
更合适的例子是
String s = "hello";
String s2 = "\"hello\"";
System.out.println(s); => hello
System.out.println(s2); => "hello"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.