android xml webservice,Android and .NET Webservice - parsing the returned xml

So I have done a few "minor" things with web services and had some success, but when I attempted to tinker around with some stuff for fun I was encountering what I believe is me incorrectly parsing out the data to get the information that I need. I can get the entire xml as a string but not just the 3 programs that I need. The getPrograms and getInstitutions are similar enough that if I can get the programs part parsed right I can get the institutions. Where I am getting confused is what I believe is the "tags" and how much they differ from any tutorials to what I am actually using. I also went the way of the XmlPullParser but do not know if this is the best way about doing this (is it?). The format of what I am accessing is as follows:

Ancillary

Ancillary ESY

REAP

And my source code is as follows:

public class FirstScreen extends Activity {

/** Called when the activity is first created. */

private static final String NAMESPACE = "http://tempuri.org/";

private static final String URL = "http://www.ces.org/android/android.asmx";//must point to where service is located

/** HelloAndroid method */

//SOAP_ACTION = NAMESPACE + METHODNAME

private static final String SOAP_ACTION = "http://tempuri.org/HelloAndroid";

private static final String METHOD_NAME = "HelloAndroid";

/** SelectInstitutionTypes method */

//SOAP_ACTION = NAMESPACE + METHODNAME

private static final String SOAP_ACTION_INSTITUTIONS = "http://tempuri.org/SelectInstitutionTypes";

private static final String METHOD_NAME_INSTITUTIONS = "SelectInstitutionTypes";

/** SelectPrograms method */

//SOAP_ACTION = NAMESPACE + METHODNAME

private static final String SOAP_ACTION_PROGRAMS = "http://tempuri.org/SelectPrograms";

private static final String METHOD_NAME_PROGRAMS = "SelectPrograms";

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

getHelloAndroid();

//getInstitutionTypes();

getPrograms();

}//end of onCreate

private void getPrograms() {

TextView tv3 = (TextView)findViewById(R.id.TextView03);//contains SelectInstitutionTypes information

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_PROGRAMS);

//soap serialization

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);//running 1.1

soapEnvelope.dotNet=true;//to handle .net services asmx/aspx

soapEnvelope.setOutputSoapObject(request);//package request

//create transport object(s)

HttpTransportSE aht = new HttpTransportSE(URL);

try

{

aht.debug = true;

//make the call

aht.call(SOAP_ACTION_PROGRAMS, soapEnvelope); //in/out

SoapObject resultString = (SoapObject)soapEnvelope.getResponse();

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

factory.setNamespaceAware(true);

XmlPullParser xpp = factory.newPullParser();

xpp.setInput(new StringReader (resultString.toString()));

int eventType = xpp.getEventType();

while(eventType != XmlPullParser.END_DOCUMENT){

if(eventType == XmlPullParser.START_DOCUMENT) {

System.out.println("Start document");

} else if(eventType == XmlPullParser.START_TAG) {

if(xpp.getName().equals("Program"))

System.out.println("Start tag "+xpp.getName());

System.out.println("Program"+ xpp.getAttributeName(0));

} else if(eventType == XmlPullParser.END_TAG) {

System.out.println("End tag "+xpp.getName());

} else if(eventType == XmlPullParser.TEXT) {

System.out.println("Text "+xpp.getText());

}

eventType = xpp.next();

}

System.out.println("End document");

tv3.setBackgroundColor(Color.BLUE);

tv3.setText("STATUS: " + resultString /*ks.toString()*/ + "\n\n" + "AHTHOST: " +

aht.getHost() + "\n\n" + "NAHT STRING: " + aht.toString());

}

catch(Exception e)

{

e.toString();

e.printStackTrace();

tv3.setText("EXCEPTION NAME: " + e.toString().toString() +

"\n\n" + "EXCEPTION MESSAGE: " + e.getMessage() + " ");

}

}//end of getPrograms

private void getInstitutionTypes() {

TextView tv2 = (TextView)findViewById(R.id.TextView02);//contains SelectInstitutionTypes information

//tv2.setText("TODO: SelectInstitutionTypes");

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_INSTITUTIONS);

//soap serialization

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);//running 1.1

soapEnvelope.dotNet=true;//to handle .net services asmx/aspx

soapEnvelope.setOutputSoapObject(request);//package request

//create transport object(s)

HttpTransportSE aht = new HttpTransportSE(URL);

try

{

aht.debug = true;

//make the call

aht.call(SOAP_ACTION_INSTITUTIONS, soapEnvelope); //in/out

SoapObject resultString = (SoapObject)soapEnvelope.getResponse();

tv2.setText("STATUS: " + resultString /*ks.toString()*/ + "\n\n" + "AHTHOST: " +

aht.getHost() + "\n\n" + "NAHT STRING: " + aht.toString());

}

catch(Exception e)

{

e.toString();

e.printStackTrace();

tv2.setText("EXCEPTION NAME: " + e.toString().toString() +

"\n\n" + "EXCEPTION MESSAGE: " + e.getMessage() + " ");

}

}//end of getInstitutionTypes

public void getHelloAndroid() {

TextView tv = (TextView)findViewById(R.id.TextView01);//contains HelloAndroid information

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

//soap serialization

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);//running 1.1

soapEnvelope.dotNet=true;//to handle .net services asmx/aspx

soapEnvelope.setOutputSoapObject(request);//package request

//create transport object(s)

HttpTransportSE aht = new HttpTransportSE(URL);

try

{

aht.debug = true;

//make the call

aht.call(SOAP_ACTION, soapEnvelope); //in/out

SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();

tv.setBackgroundColor(Color.BLUE);

tv.setText("STATUS: " + resultString + "\n\n" + "AHTHOST: " +

aht.getHost() + "\n\n" + "NAHT STRING: " + aht.toString());

}

catch(Exception e)

{

e.toString();

e.printStackTrace();

tv.setText("EXCEPTION NAME: " + e.toString().toString() +

"\n\n" + "EXCEPTION MESSAGE: " + e.getMessage() + " ");

}

}//end of getHelloAndroid

}//end of activity

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值