[英]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.