3

我有文本视图 Java 代码和肥皂。

但我想要一个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>

我正在连接到在线网络服务。帮助我如何使用 Ksoap2 解析 xml。

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

邮件.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());
    }

}
}

日志猫

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.
4

3 回答 3

2

试试下面的链接

http://android.vexedlogic.com/2011/04/30/android-lists-v-accessing-and-sumption-a-soap-web-service-ii/

合适的代码试试这个。

于 2013-03-13T06:43:06.053 回答
0

你可以参考下面的链接,它解释了如何用 ksoap 处理复杂的对象数组:

http://seesharpgears.blogspot.in/2010/10/web-service-that-returns-array-of.html

在这个例子中,他解释了如何从肥皂响应中获取对象列表,

之后,如果您想在列表视图中显示数据,可以将该列表传递给您的列表视图

于 2013-03-13T06:35:19.497 回答
0

尝试使用“androidHttptransport.responseDump”,因为它提供 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();
于 2013-04-13T14:12:46.857 回答