简体   繁体   English

当我在字符串中插入XML Soap请求时,为什么Eclipse给我一个错误?

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

相关问题 当我尝试运行示例应用程序时,为什么eclipse给我错误? - Why does eclipse give me errors when i try to run sample application? 为什么Eclipse在返回后总是给我一个错误; - Why does Eclipse always give me an error after return; 为什么eclipse会让我的return语句出错? - Why does eclipse give me an error with my return statement? 有没有办法让我将此肥皂请求作为java中的xml传递? - is there a way for me to pass this soap request as a xml in java? 为什么 hibernate 在我放置 transient 标签时会给我这个错误? - Why does hibernate give me this error when I put the transient tag? 将XML嵌入SOAP请求中的CDATA部分时解析错误 - Parse error when embedding XML into the CDATA section in a SOAP Request 为什么 eclipse 在我写 public static void main(String[] args) 的行中显示错误 - Why eclipse show me error in the line where i have written public static void main(String[] args) 为什么即使我声明了 rand,它也会给我一个错误? - Why does it give me an error even though I declared rand? 为什么 snsClient.unsubscribe(request) 在 snsClient.unsubscribe(request) 上给我一个错误? - Why snsClient.unsubscribe(request) did give me a error on snsClient.unsubscribe(request)? 当我显式使用另一个类中的一个类的公共函数时,为什么Java没有给我编译错误 - Why java doesn't give me compile error when I use public functions of one class in another class explicitly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM