【发布时间】:2023-03-09 06:54:01
【问题描述】:
我对 Android 应用开发非常陌生。在我的新 Android 应用程序中,我想显示一些来自 web 服务的数据。这意味着我有一个SOAP message,我需要解析来自 SOAP 响应的数据。在 iPhone 应用程序中,我非常了解解析 SOAP 消息响应,但是在 android 中我不知道该怎么做?我在谷歌上搜索了很多并得到了一些想法。但是,我对此非常困惑。谁能建议任何最简单的方法来理解 SOAP 发送请求/接收响应并解析(XML format)SAXParser 中的响应 Android?我在我的项目中安装了ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar。在这里我找到了一些示例代码,我在这里发布,
import java.io.*;
import org.ksoap2.SoapEnvelope;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParserException;
public class ParsingSteps
{
public static void main(String[] args)
{
try{
// String msg="<hello>World!</hello>";
String msg = "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\"http://
www.w3.org/2001/12/soap-envelope\" " + "xmlns:xsi=\"http://www.w3.org/
2001/XMLSchema-instance <http://www.w3.org/%0A2001/XMLSchema-instance>\""
+"xmlns:xsd=\"http://www.w3.org/2001/
XMLSchema\"& gt;" +
"<SOAP-ENV:Body>" +
"<result>" +
"<message xsi:type=\"xsd:string\">Hello World</message>" +
"</result>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
// byte[] in= msg.getBytes();
KXmlParser parser=new KXmlParser();
parser.setInput(new StringReader(msg));
SoapEnvelope soapenvelope= new SoapEnvelope
(SoapEnvelope.VER12);
//soapenvelope.parse(parser);
soapenvelope.parseBody(parser);
}
catch (IOException e) {
System.out.println("Error reading URI: " + e.getMessage ());
} catch (XmlPullParserException e) {
System.out.println("Error in parsing: " + e.getMessage ());
}
// String result=parser.getName();
//System.out.println(result);
}
}
这是正确的代码。请对我的问题提出任何建议。请帮助我。提前致谢。
【问题讨论】:
标签: android soap xml-parsing httpresponse