• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Parsing XML in my Android App - Help Please!

 
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, new here and new to programming.  I've been using Stack Overflow, but I'm realising they aren't so tolerant with someone like myself asking lots of newbie questions, even though I've done hours of searching for my answer.

Anyway, to my issue.  I am writing an Android app that in part of it I would like to download traffic information.  I have a link to an xml file I can use - http://m.highways.gov.uk/feeds/rss/AllEvents.xml

For now though, I've downloaded this xml file and put it in my res folder.  I'll come to parsing it without downloading if we can fix the first issue

Now, at the moment I have a SAXHandler that looks like this -



Then in my main activity I have -



The error I get is -

org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: syntax error

So it looks like me first issue is my parser doesn't like the xml format?

If we can figure that, I would like to then know how to a) download this xml as the user opens the activity or b) parse it direct?

Thanks for any help you might be able to offer a struggling noob!
 
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A StringReader uses as its input the string used to create it. That would be "allevents.xml" rather than the contents of the file called "allevents.xml". I think you need a FileReader instead.

As to the Android-related question, please start a separate topic in the Android forum.
 
Andy Crowther
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.  Makes sense.

I've made that change, I've tried moving the xml into an xml folder in Res and changed the code to be new FileReader("xml/allevents.xml") but I still get -

java.io.FileNotFoundException: xml/allevents.xml (No such file or directory)

Where should the file be?
 
Tim Moores
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not how files are accessed in Android. Files should go into the "raw" directory, and then you would access them via something like this:


Please post any further Android-specific follow-up questions to the Android forum.
 
Andy Crowther
Ranch Hand
Posts: 70
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome, thanks for the help.  I'm getting there now!
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic