gpt4 book ai didi

java - 当我在字符串中插入此 XML Soap 请求时,为什么 Eclipse 会给出错误?

转载 作者:行者123 更新时间:2023-12-01 13:48:58 25 4
gpt4 key购买 nike

我对 Java 中的 SOAP Web 服务还很陌生,并且遇到以下问题。

我有一种为REQUEST创建SOAP Envelop的方法,这个:

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 字符串中的每个 " 转义为 \"

WRONG:
String soapXml = "<soapenv:Envelope xmlns:soapenv="http://sc ... to be continued

CORRECT:
String soapXml = "<soapenv:Envelope xmlns:soapenv=\"http://sc ... to be continued

关于java - 当我在字符串中插入此 XML Soap 请求时,为什么 Eclipse 会给出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20118964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com