aspose file tools
The moose likes Android and the fly likes parsing XML data from weather RSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "parsing XML data from weather RSS" Watch "parsing XML data from weather RSS" New topic

parsing XML data from weather RSS

casio freas

Joined: May 16, 2010
Posts: 5
hello everyone. i beginner in android & java programming.

i'm trying build some weather report apps for Android.
i think (i do) the easiest way to modifying the WeatherReporter project from ebook Unlocking Android - A Developer’s Guide, Manning because the project are using API Yahoo Weather (those only works on US region only). instead of, i rather use other Weather API from that available international weather report data.

1. the problem is i'm still beginning learning parsing XML data using package org.xml.sax as SAX handler for API bean.

these the request URL format (to able accessing it, needed to register for free) :
sample :

(the key are my registered ID number, it required in every request)

then it gave XML data bean :

after i learning from some manual (because the site/owner API only gave .NET sample code, instead implemented in java), i modify the Handler class to able working for API
these are the code :

the every text data can be read it using getAttributeValue method.
i admit that the code doesn't work to read the API from.

but those code the best i know to resolve it or knowing other manual that have solution reading for those similar XML data.
i hope anyone can help to resolve these problem , at least the right way to read data x inside every element and on sub element :

and i hope someone gave manual reference with sample code to reading XML data for implemented in android/java.

the i want to ask how to pasing XML data from
these are the XML data

2. next i want to ask how to change the string link using local data from res/drawable/image.png instead downloading image from a web URL (from

these are the code :

i've try change

by using

those i realize, it just gave integer value output because from generated class

how to change it to locally accessed as link URL name ?
or are able to mixed using cache handlers of sprites /drawables

i hope someone respond it sooner.
last, sorry for my bad english
Lester Burnham

Joined: Oct 14, 2008
Posts: 1337

<element b> x </element b>

The way to get at the value "x" is to use the SAX characters methods - which your code has, but which currently does nothing. Have it do a "System.out.println(ch)" and you should see those values.
casio freas

Joined: May 16, 2010
Posts: 5
thanks for advice, i have inserting the function in "characters" method :

and correcting the others. Then the fully code (as WorldWeatherHandler.class), become like these :

but after compile. it result doesn't gave output value (from the android app), the display like these :

these are output display before i modify it (from the original source using API yahoo wheather) :

how to substitute "System.out.println(ch)" method ?
since android doesn't have an the console output.

i have try using sample code from, to using "println" but it can't compile/run.
i hope you know how to made /know the samples code standard java of implementing class org.xml.sax for parsing XML data.

and what are the mistakes from my code of reading those above XML structure ?
Lester Burnham

Joined: Oct 14, 2008
Posts: 1337
since android doesn't have an the console output.
Sure it does, it's called the log. See the android.util.Log class for how to print something to it, and the documentation of the "adb" tool for how to view it (specifically, "adb logcat").

It'a hard to say what the problem is; are the SAX methods being called at all?
casio freas

Joined: May 16, 2010
Posts: 5
thanks for the advice for using "adb logcat". but still almost all the XML data can be readed,
and other tag part can't be readed, those are :

on part "startElement" method i use logical "if" rather than "else if" because some part called twice, an some part be skipped (i also commented and ask from the suspicious alogarithm at some line that maybe wrong ) :

and on endElement method i use (i think these part doesn't have wrong alogarithm) :

then on characters method i use :

and last is the fact log from "adb logcat" :

i very appreciate of your assistance to resolve my problem.

I agree. Here's the link:
subject: parsing XML data from weather RSS
It's not a secret anymore!