String tagName = xpp.getName();
I think this line shouldn't be inside
if(eventType==XmlPullParser.START_TAG)
Example Here: http://www.vogella.com/tutorials/AndroidXML/article.html
Question
I'm trying to parse xml from this url
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22MSFT%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
and while using the methods getName()
and all it gives the null
value.
Below is the code that is in thread, could you please tell me where the error is.
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
String urlString = arg0[0];
String text = null;
InputStream is = null;
//String tagName = null;
int count = 0;
try {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(10*1000);
connection.setConnectTimeout(10*1000);
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.connect();
int response = connection.getResponseCode();
Log.d("debug", "the response is"+response);
is = new BufferedInputStream(connection.getInputStream());
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(is, null);
int eventType = xpp.getEventType();
Log.d("kchayar", is+"");
while(eventType != XmlPullParser.END_DOCUMENT){
String tagName = xpp.getName();
if( eventType == XmlPullParser.START_TAG ){
// if( tagName.equals("Change")){
// text = xpp.nextText();
count ++;
// }
}
if( eventType == XmlPullParser.TEXT ){
// if( tagName.equals("Change")){
text = xpp.nextText();
count ++;
//}
}
eventType = xpp.next();
}
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
wv.setText(result);
}
}
La solution
String tagName = xpp.getName();
I think this line shouldn't be inside
if(eventType==XmlPullParser.START_TAG)
Example Here: http://www.vogella.com/tutorials/AndroidXML/article.html