我遇到了一个问题,在我的程序中我得到了xmlpullparser异常并且我对它进行了护目镜但是因为我是android的新手我无法理解如何解决这个问题。我纠正了我的程序很多我还不能,有人帮我解决这个问题
我正在使用WSDL,KSOAP1.2。
提前致谢....!
这是我的代码
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();
}
}
}
这些是logcat消息
06-20 18:12:23.099: WARN / System.err的(688): org.xmlpull.v1.XmlPullParserException: 预计:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (位置: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(未知 来源)06-20 18:12:23.108: WARN / System.err(688):at org.ksoap2.transport.Transport.parseResponse(未知 来源)06-20 18:12:23.108: WARN / System.err(688):at org.ksoap2.transport.HttpTransportSE.call(未知 来源)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)
答案 0 :(得分:0)
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();
}