我做了一个WEBService,ANDROID使用SOAP2调用WEB的方法,WEB返回一个XML。我在ANDROID中,使用SAX解悉时,可以运行到startDocument之后就不再解悉,这是为何?有无高人帮下忙~
如下:
调用WEB
public  String myrr(String p1){
     SoapObject request =new SoapObject(namespace,name);
     String str = null;
     SoapObject result =null;
  request.addProperty("zyh",p1);
  SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
  envelope.bodyOut = request;
  envelope.dotNet = true;
  envelope.setOutputSoapObject(request);
  HttpTransportSE ht=new HttpTransportSE(URL);
  try {
   ht.call(namespace+name,envelope);
   result =(SoapObject)envelope.bodyIn; 
   envelope.setOutputSoapObject(result);
   //str=result.toString();
   str=result.getProperty(0).toString();
   //str=result.getProperty(0).toString();
   //rs=result.getProperty(0).toString();
   //tv2.setText(rs);
  } catch (IOException e) {
   // TODO Auto-generated catch block
  } catch (XmlPullParserException e) {
   // TODO Auto-generated catch block 
  }
  
  return str;
    }
监听器:
class listener implements OnClickListener{  
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   String str;
   str= myrr("123123");
   System.out.println(str);
   try{
    SAXParserFactory factory=SAXParserFactory.newInstance();
    XMLReader reader = factory.newSAXParser().getXMLReader();
    System.out.println("start");
    reader.setContentHandler(new MyContentHandler());
    System.out.println("end");
    reader.parse(new InputSource(new StringReader(str)));
   }
   catch(Exception e){
    e.printStackTrace();
   }
  }解悉的代码。public class MyContentHandler extends DefaultHandler {@Override
public void characters(char[] ch, int start, int length)
   throws SAXException {
  // TODO Auto-generated method stub
  super.characters(ch, start, length);
  System.out.println("3");
}
@Override
public void endDocument() throws SAXException {
  // TODO Auto-generated method stub
  super.endDocument();
  System.out.println("5");
}
@Override
public void endElement(String uri, String localName, String qName)
   throws SAXException {
  // TODO Auto-generated method stub
  super.endElement(uri, localName, qName);
  System.out.println("4");
  if (localName.equals("l0")){
   
  }