XmlPullParserException: expected: START_TAG

5114 views
Skip to first unread message

Pankaj Deshpande

unread,
Feb 2, 2010, 3:57:23 AM2/2/10
to android-d...@googlegroups.com
Hi all,
I am developing an application which uses KSOAP2 with Android 2.0. But I am getting error 
"org.xmlpull.v1.XmlPullParserException: expected: START_TAG"

can anyone tell me why this is happening??

Regards,
Pankaj Deshpande

--
Android Application Developer
Ruby Solutions, Pune.
09823637153

Galeol

unread,
Feb 3, 2010, 9:47:40 AM2/3/10
to Android Developers
Hi Pankaj!

Have you checked if your xml file is well-formed?

Nicholas Albion

unread,
Feb 3, 2010, 5:29:43 PM2/3/10
to Android Developers
If you determine that the problem is that the XML (or HTML!) is badly
formatted and you have no control over it, you can do something like:

int n;
while( (n = xpp.getNext()) != END_DOCUMENT ) {
try {
// do your parsing element-by-element
} catch( org.xmlpull.v1.XmlPullParserException e ) {} // ignore the
exception
} catch( Throwable e ) {
log.warning("error while parsing file: " + e.getMessage(); //
you may want to catch any other exceptions and do something about them
}
}

It might not be the most efficient practice to perform the try/catch
within the loop, but if somebody else is sending you dodgy XML there
might not be anything you can do.

Kevin Duffey

unread,
Feb 4, 2010, 12:40:40 AM2/4/10
to android-d...@googlegroups.com
Like the others said.. it sounds like a starting element is not being found before either some text or an end tag. Usually you'll see that error with something like:

<node1>
  </node2>
  <node3>
   </node3>
</node1>

Or

<node1>
</node1>
  some text
<node2>
</node2>

It ALSO depends on how you are moving thru the xml parser.. if you are using parser.next() you are moving one parsing element at a time, which means you'll find every possible element including text, tags,white space, etc. If you use parser.nextTag() you may skip over that 2nd example text issue and find node2 start tag.



--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-develop...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Shrenik Vikam

unread,
Feb 4, 2010, 7:05:18 AM2/4/10
to Android Developers
how to get the xpp object ?

Pankaj Deshpande

unread,
Feb 4, 2010, 7:23:26 AM2/4/10
to Android Developers
Hello,
When I use SoapEnvelope.VER11, it works fine, But when I use
SoapEnvelope.VER12, it gives me error:
"org.xmlpull.v1.XmlPullParserException: expected: START_TAG".
This is my code...


import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;

import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;


import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MyWebService extends Activity {
private static final String SOAP_ACTION = "http://your_URL/
your_mathod_name";
private static final String METHOD_NAME = "your_mathod_name";
private static final String NAMESPACE = "http://your_URL/";
private static final String URL = "http://your_URL/WebService.asmx?
WSDL";
private Object resultRequestSOAP = null;
String data = "some data";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
setContentView(tv);
try {

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.encodingStyle = SoapSerializationEnvelope.ENC2001;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
request.addProperty(METHOD_NAME, data);
envelope.bodyOut = request;
SoapObject response = null;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
// get the data
response = (SoapObject) envelope.bodyIn;

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}

}
}

Can u tell me why is this happening with SOAP1.2 ?
Do I need to specify some encoding style for SOAP1.2 ?

Regards,
Pankaj.

> > android-develop...@googlegroups.com<android-developers%2Bunsubs cr...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages