2013-03-13 63 views
3

我有文本视图Java代码和soap。如何在android中解析SOAP列表

但我想要一个ListView。如何解析Android中的肥皂清单。

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-service.Help我如何分析利用Ksoap2的XML。

解析soap,就像只显示列表中的数据一样。

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

你有什么问题?你是否从肥皂请求得到正确的回应? – 2013-03-13 06:16:13

+1

@Sangeetha你的xml作为sosap请求的响应,你想解析和显示列表视图中的项目? – Raghunandan 2013-03-13 06:23:40

+0

@Bhavesh是的,但通过肥皂 – Sangeetha 2013-03-13 06:25:53

回答

0

尝试使用“androidHttptransport.responseDump”,因为它提供了xml formate并使用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();