• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

parsing XML data from weather RSS

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 www.worldweatheronline.com 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 worldweatheronline.com bean.

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

http://www.worldweatheronline.com/feed/weather.ashx?q=singapore&format=xml&num_of_days=2&key=240001503b080202101211

(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 worldweatheronline.com
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 worldweatheronline.com
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 http://go.to.web/weatherimages/image.png).

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
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 www.saxproject.org/quickstart.html, 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
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

regards.
reply
    Bookmark Topic Watch Topic
  • New Topic