24,923
社区成员
发帖
与我相关
我的任务
分享
testButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
SoapObject request1 = new SoapObject(space, "queryStudents");
//request1.addProperty("name", "小明");
HttpTransportSE ht1 = new HttpTransportSE(
"http://192.168.1.3:8080/axis2/services/MyService");
ht1.debug = true;
SoapSerializationEnvelope envelope1 = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope1.bodyOut = request1;
envelope1.dotNet = true;
envelope1.setOutputSoapObject(request1);
//envelope1.encodingStyle = "UTF-8";
ht1.call(space_name, envelope1);
//把返回值(xml格式)强制转化为Object类型
//Object object1 = (Object) envelope1.getResponse();
SoapObject object1 = (SoapObject)envelope1.bodyIn;
String info2 = object1.getProperty(0).toString();
System.out.println("info2--->" + info2);
//对于返回值有多个内容是,可以考虑解析xml
String info1 = envelope1.bodyIn.toString();
System.out.println("result--->" + info1);
try{
//创建一个SAXParserFactory(写法已规定好)
SAXParserFactory factory = SAXParserFactory.newInstance();
//创建XML的一个对象(写法已规定好)作用:逐行扫描xml文件
XMLReader reader = factory.newSAXParser().getXMLReader();
//为XMLreader设置内容处理器,利用继承来实现DefaultHandler接口里面的一些方法
reader.setContentHandler(new MycontenHander());
//开始解析XML文件
reader.parse(new InputSource(new StringReader(info1)));
//reader.parse(inputSource);
}
catch(Exception e){
e.printStackTrace();
}
} catch (HttpResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
<ns:queryStudentsResponse xmlns:ns="http://service" xmlns:ax21="http://entity/xsd">
<ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:Student">
<ax21:address>南京</ax21:address>
<ax21:id>1</ax21:id>
<ax21:name>小明</ax21:name>
<ax21:number>1</ax21:number>
<ax21:tel>119</ax21:tel>
</ns:return>
<ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:Student">
<ax21:address>西藏</ax21:address>
<ax21:id>2</ax21:id>
<ax21:name>小郭</ax21:name>
<ax21:number>2</ax21:number>
<ax21:tel>110</ax21:tel>
</ns:return>
<ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:Student">
<ax21:address>朝鲜</ax21:address>
<ax21:id>3</ax21:id>
<ax21:name>坤哥</ax21:name>
<ax21:number>3</ax21:number>
<ax21:tel>117</ax21:tel>
</ns:return>
<ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:Student">
<ax21:address>加拿大</ax21:address>
<ax21:id>4</ax21:id>
<ax21:name>张三</ax21:name>
<ax21:number>0</ax21:number>
<ax21:tel>120</ax21:tel>
</ns:return>
</ns:queryStudentsResponse>
复制代码
@Override
public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
// TODO Auto-generated method stub
System.out.println("Qname------>" + qName);
System.out.println("Localname------>" + localName);
tagName = localName;
if (localName.equals("return")) {
for (int i = 0; i < atts.getLength(); i++) {
System.out.println(atts.getLocalName(i) + atts.getValue(i));
}
}
}
复制代码