我有文本视图Java代码和soap。
但我想要一个ListView。如何在Android中解析soap列表。
SOAP 1.1请求和响应
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>
<FormModel>
<Text1>string</Text1>
<Text2>string</Text2>
<Text3>string</Text3>
</FormModel>
<FormModel>
<Text1>string</Text1>
<Text2>string</Text2>
<Text3>string</Text3>
</FormModel>
</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>
我正在连接到在线web服务。帮助我如何使用Ksoap2解析xml。
解析肥皂,就像只在列表中显示数据一样。
Mail.java
public class Main extends Activity {
private static String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "HelloWorld";
private static String URL = "http://sygnetinfosol.com/webservice.asmx?WSDL";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
// Make the soap call.
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null){
TextView t = (TextView)this.findViewById(R.id.resultbox);
t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
}
}
}
logcat的
03-13 06:50:57.077: I/Choreographer(2933): Skipped 114 frames! The application may be doing too much work on its main thread.
03-13 06:50:57.669: I/Choreographer(2933): Skipped 82 frames! The application may be doing too much work on its main thread.
03-13 06:50:57.787: I/Choreographer(2933): Skipped 91 frames! The application may be doing too much work on its main thread.
03-13 07:16:37.837: E/Trace(3374): error opening trace file: No such file or directory (2)
03-13 07:16:39.008: I/System.out(3374): MY SOAP RESPONE ISanyType{FormModel=anyType{Text1=12.9174948; Text2=77.5989675; Text3=JayDeva Hospital,Karnataka,Bangalore,India; }; FormModel=anyType{Text1=12.9274529; Text2=77.590597; Text3=9th Block,Central Mall,Jayanagar,Karnataka,Bangalore,India; }; FormModel=anyType{Text1=12.9285212; Text2=77.5834339; Text3=Jayanagar 4th Block,Karnataka,Bangalore,India; }; FormModel=anyType{Text1=12.961085; Text2=77.60469269; Text3=BTM Layout,Richmod Towr,Karnataka,Bangalore,India; }; }
03-13 07:16:39.117: D/dalvikvm(3374): GC_CONCURRENT freed 177K, 11% free 2590K/2908K, paused 80ms+5ms, total 201ms
03-13 07:16:39.438: I/Choreographer(3374): Skipped 347 frames! The application may be doing too much work on its main thread.
03-13 07:16:39.458: D/gralloc_goldfish(3374): Emulator without GPU emulation detected.
03-13 07:16:39.638: I/Choreographer(3374): Skipped 44 frames! The application may be doing too much work on its main thread.
03-13 07:16:40.437: I/Choreographer(3374): Skipped 74 frames! The application may be doing too much work on its main thread.
答案 0 :(得分:2)
请尝试以下链接
这是合适的代码试试这个。
答案 1 :(得分:0)
你可以参考下面的链接,它解释了如何使用ksoap处理复杂的对象数组:
http://seesharpgears.blogspot.in/2010/10/web-service-that-returns-array-of.html
在这个例子中,他解释了如何从soap响应中获取对象列表,
之后,如果要在listview中显示数据,可以将该列表传递给列表视图
答案 2 :(得分:0)
尝试使用“android Httptransport.response Dump”,因为它提供xml格式并使用Dom Parser解析responsedump并根据需要放入listView。
String response = androidHttpTransport.responseDump;
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(response));
doc = db.parse(is);
doc.getDocumentElement().normalize();
// Node hh=doc.getElementsByTagName("hhCompany").item(0).;
org.w3c.dom.Element ee = doc.getDocumentElement();