问题
I got stuck with a problem, In my program I am getting the xmlpullparser exception and I goggled it but as I am new to android I couldn't able to understand how to solve the issue. I corrected my program a lot still I couldn't, some one help me to solve this
I am using WSDL,KSOAP1.2.
Thanks in advance....!
Here is my code
public void register() {
Log.v(TAG, "Trying to Login");
EditText etxt_user = (EditText) findViewById(R.id.regetfirstname);
EditText etxt_pass = (EditText) findViewById(R.id.regetlastname);
EditText etxt_dob = (EditText) findViewById(R.id.regetdob);
EditText etxt_email = (EditText) findViewById(R.id.regetemail);
EditText etxt_password = (EditText) findViewById(R.id.regetpwd);
EditText etxt_confirmpassword = (EditText) findViewById(R.id.regetrepwd);
EditText etxt_mobno = (EditText) findViewById(R.id.regetmobno);
final Button regmalebtn = (Button) findViewById(R.id.regmalebtn);
Button regfemalebtn = (Button) findViewById(R.id.regfemalebtn);
// String deviceid = null;
String fname = etxt_user.getText().toString();
String lname = etxt_pass.getText().toString();
String dob = etxt_dob.getText().toString();
String contact = etxt_mobno.getText().toString();
String password;
String confirmpassword ;
String email = etxt_email.getText().toString();
password = etxt_password.getText().toString();
confirmpassword = etxt_confirmpassword.getText().toString();
final SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL);
try {
// boolean pstatus = false;
if (confirmpassword != null && password != null)
{
if (password.equals(confirmpassword))
{
request.addProperty("password", password);
}
}
regmalebtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// String gender = regmalebtn.getText().toString();
String gender;
gender = ((Button)findViewById(R.id.regmalebtn)).getText().toString();
gender.equals("male");
request.addProperty("gender", gender);
}
});
regfemalebtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// String gender = regmalebtn.getText().toString();
// request.addProperty("gender", gender);
String gender;
gender = ((Button)findViewById(R.id.regfemalebtn)).getText().toString();
gender.equals("female");
request.addProperty("gender", gender);
}
});
request.addProperty("email", email);
request.addProperty("contact", contact);
request.addProperty("fname", fname);
request.addProperty("lname", lname);
request.addProperty("dateofbirth", dob);
//request.addProperty("password", "password");
request.addProperty("latitude", 76);
request.addProperty("longitude", 82);
request.addProperty("device_id", "12345");
aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
aht.call(SOAP_ACTION, soapEnvelope);
// SoapObject result = (SoapObject)soapEnvelope.getResponse();
SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;
Log.v("TAG", String.valueOf(resultsRequestSOAP));
//String resultData;
// resultData = request.getProperty(0).toString();
} catch (Exception e) {
e.printStackTrace();
}
}
}
These are the logcat messages
06-20 18:12:23.099: WARN/System.err(688): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @1:6 in java.io.InputStreamReader@43e88978) 06-20 18:12:23.099: WARN/System.err(688): at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273) 06-20 18:12:23.108: WARN/System.err(688): at org.kxml2.io.KXmlParser.require(KXmlParser.java:1431) 06-20 18:12:23.108: WARN/System.err(688): at org.ksoap2.SoapEnvelope.parse(Unknown Source) 06-20 18:12:23.108: WARN/System.err(688): at org.ksoap2.transport.Transport.parseResponse(Unknown Source) 06-20 18:12:23.108: WARN/System.err(688): at org.ksoap2.transport.HttpTransportSE.call(Unknown Source) 06-20 18:12:23.118: WARN/System.err(688): at com.soap.Register.register(Register.java:189) 06-20 18:12:23.118: WARN/System.err(688): at com.soap.Register$1$1.run(Register.java:42)
回答1:
public static void getAllXML(String url) throws
XmlPullParserException, IOException, URISyntaxException{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(new InputStreamReader(getUrlData(url)));
XmlUtils.beginDocument(parser,"results");
int eventType = parser.getEventType();
do{
XmlUtils.nextElement(parser);
parser.next();
eventType = parser.getEventType();
if(eventType == XmlPullParser.TEXT){
Log.d("test",parser.getText());
}
} while (eventType != XmlPullParser.END_DOCUMENT) ;
}
public InputStream getUrlData(String url)
throws URISyntaxException, ClientProtocolException, IOException {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet(new URI(url));
HttpResponse res = client.execute(method);
return res.getEntity().getContent();
}
来源:https://stackoverflow.com/questions/6411577/android-xmlpullparser-exception