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 9233891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:39:34+00:00 2026-06-18T06:39:34+00:00

I am trying to parse some data from the following site, to an Android

  • 0

I am trying to parse some data from the following site, to an Android App which I am creating

TFL Tube Data

The data in this feed is constantly updated and can hold anything from nothing to 15/16 items. The basic format of each item is as following:

<ArrayOfLineStatus> - BEGINNING OF XML DOCUMENT    
    <LineStatus ID="10" StatusDetails="No service this weekend due to planned engineering work.">
        <BranchDisruptions/>
        <Line ID="7" Name="Circle"/>
        <Status ID="CS" CssClass="DisruptedService" Description="Planned Closure" IsActive="true">
            <StatusType ID="1" Description="Line"/>
        </Status>
    </LineStatus>
<ArrayOfLineStatus> - END OF XML DOCUMENT

I need to go through the entire and pull the value of the attribute of “Name” in Line and “Description” in “Status”. So in the above I would be pulling “Circle” and “Planned Closure”. The classes I have made so far is as follows:

Main Class

    public class TubeStatusXMLParsing  extends Activity {

        static final String baseURL = "http://cloud.tfl.gov.uk/TrackerNet    
                                          /LineStatus/IncidentsOnly";
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle icicle) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build(); 
            StrictMode.setThreadPolicy(policy);
            super.onCreate(icicle);
            setContentView(R.layout.tube_status);
            getStatus();        
            }

       public void getStatus() {
        // TODO Auto-generated method stub
        try{
            URL website = new URL(baseURL);
            //getting xmlreader to parse data
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            HandlingXMLStuff doingWork = new HandlingXMLStuff();
            xr.setContentHandler(doingWork);
            xr.parse(new InputSource(website.openStream()));
            String listofStatuses = doingWork.getInformation();
            circleStatus.setText(listofStatuses);
        }catch (Exception e){
            circleStatus.setText("error");
        }
    }
}

Handling XML

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.sax.Element;
import android.sax.RootElement;

public class HandlingXMLStuff extends DefaultHandler {

    private ArrayList<String>statuses = null;
    String status;
    String lineName;

    public String getInformation(){
        return statuses.get(0);
    }

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        if(qName.equalsIgnoreCase("ArrayOfLineStatus")){
            statuses = new ArrayList<String>();
        }else if(qName.equalsIgnoreCase("Status")){
            status = attributes.getValue("Status");
            statuses.add(status);
            }

        }

Any Help on this would be greatly appreciated

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-18T06:39:35+00:00Added an answer on June 18, 2026 at 6:39 am

    It is hard to understand what you need, but you are getting the attributes wrong.
    I think it should somehow like this

    else if (qName.equalsIgnoreCase("Status")) {
        object = new Status();
        object.id = attributes.getValue("ID");
        object.cssClass = attributes.getValue("CssClass");
        object.isActive = attributes.getValue("IsActive");
        object.description = attributes.getValue("Description");
    }
    else if (qName.equalsIgnoreCase("StatusType")) {
        object.typeId = attributes.getValue("ID");
        //etc, and maybe the StatusType should be a nested class of Status and stored in array field
    }
    

    And in your endElement

    if (qName.equalsIgnoreCase("Status")) {
        statuses.add(object);
    }
    

    I’m too lazy to write the whole thing, I wrote it just to show how to get attributes.
    Also, I prefer using android.sax instead of directly creating the DefaultHandler.

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

Sidebar

Related Questions

I am trying to parse some data from external site to local script. Local
I'm trying to parse some JSON data, and I'm using the examples from this
I am trying to parse some data from ifconfig output with sed, but I
I'm trying to parse some data returned by a 3rd party app (a TSV
I'm getting the following error when trying to add some data from myXml.xml to
I'm trying to parse RSS feed from this link http://www.gazetaexpress.com/rss.php?cid=1,13&part=rss but when i try
I have a small issue while trying to parse some data from a table.
I'm trying to parse some JSON data from the Google AJAX Search API. I
I'm trying to parse out some data thats returned from a web service via
I am trying to parse some output data from and PBX and I have

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.