Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:08:44+00:00 2026-06-04T00:08:44+00:00

I’m trying to parse XML with Android’s own parser. I am using the IBM

  • 0

I’m trying to parse XML with Android’s own parser. I am using the IBM tutorial as a guide when doing this.

THE CODE

The XML I’m testing with is with the following link. I am trying to parse Number and Name from it.

https://api.trafiklab.se/sl/realtid/GetSite?stationSearch=Slussen&key=7c4434c36d394e0c99396b8d1c69d9c4

I have set up a parser class called AndroidSaxFeedParser that looks like this:

public class AndroidSaxFeedParser extends BaseFeedParser {

    static final String ROOT = "http://www1.sl.se/realtidws/";
    public AndroidSaxFeedParser(String feedUrl) {
        super(feedUrl);
    }

    public List<Message> parse() {
        final Message currentMessage = new Message();
        RootElement root = new RootElement(ROOT, "Hafas");
        final List<Message> messages = new ArrayList<Message>();
        Element sites = root.getChild(SITES);
        Element site = sites.getChild(SITE);

        site.setEndElementListener(new EndElementListener(){
            public void end() {
                messages.add(currentMessage.copy());
            }
        });

        site.getChild(NUMBER).setEndTextElementListener(new EndTextElementListener(){
            public void end(String body) {
                currentMessage.setNumber(body);
            }
        });

        site.getChild(NAME).setEndTextElementListener(new EndTextElementListener(){
            public void end(String body) {
                currentMessage.setName(body);
            }
        });

        try {
            Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return messages;
    }
}

The BaseFeedParser that the above class extends looks like this:

public abstract class BaseFeedParser implements FeedParser {

    // names of the XML tags
    static final String SITES = "Sites";
    static final  String SITE = "Site";
    static final  String NUMBER = "Number";
    static final  String NAME = "Name";

    private final URL feedUrl;

    protected BaseFeedParser(String feedUrl){
        try {
            this.feedUrl = new URL(feedUrl);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    protected InputStream getInputStream() {
        try {
            return feedUrl.openConnection().getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

I call the parser like this:

AndroidSaxFeedParser parser = new AndroidSaxFeedParser("https://api.trafiklab.se/sl/realtid/GetSite?stationSearch=Slussen&key=7c4434c36d394e0c99396b8d1c69d9c4");
List<Message> messages = parser.parse();

(I’m not including the Message class since the problem shouldn’t be there, it never gets a chance to process the messages)

THE PROBLEM

None of the listeners in the AndroidSaxFeedParser ever hear anything. When I place breakpoints inside them, they are never triggered. I see that the Elements sites and site are picked up properly (I can see relevant data in the variables). It runs down to the final Xml.parse() line which executes properly but returns a blank result.

Any ideas where I’m going wrong? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:08:45+00:00Added an answer on June 4, 2026 at 12:08 am

    Well I was unable to get it working with Android’s SAX parser so I switched to the XmlPullFeedParser class instead, also according to IBM’s examples. This worked without any problems. Cheap solution, but it will have to do.

    I’d post the code, but while testing it I also switched to a different XML call so the parsing is different from the above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.