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

  • Home
  • SEARCH
  • 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 3957106
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:26:56+00:00 2026-05-20T02:26:56+00:00

I am trying to read an XML from the web and display them in

  • 0

I am trying to read an XML from the web and display them in a Listview. In the XML I have 3 records and my Listview only showing the last record. Would be great if anyone can help me identifying the mistakes!!
I am using SAX to read from the web.

Handler:

public class SearchItemHandler extends DefaultHandler{
private boolean in_itemName=false;
private boolean in_itemAddress=false;
private boolean in_itemLatitude=false;
private boolean in_itemLongitude=false;
private boolean in_business=false;
private boolean in_local=false;

private SearchItem sItem=new SearchItem();
public SearchItem getParsedData(){
    return this.sItem;
}
    public static List<SearchItem> list=new ArrayList<SearchItem>();

@Override
public void startDocument() throws SAXException {
        this.sItem = new SearchItem();
}

@Override
public void endDocument() throws SAXException {
        // Nothing to do
}
@Override
public void startElement(String namespaceURI,String localname,String qName,Attributes atts)throws SAXException{
    if(localname.equalsIgnoreCase("Business")){
        this.in_business=true;
    }else if(localname.equalsIgnoreCase("local")){
        this.in_local=true;
    }else if(localname.equalsIgnoreCase("ItemName")){
        String itemname=atts.getValue("name");
        sItem.setItemName(itemname);
        this.in_itemName=true;
    }else if(localname.equalsIgnoreCase("ItemAddress")){
        String itemaddress=atts.getValue("address");
        sItem.setItemAddress(itemaddress);
        this.in_itemAddress=true;
    }else if(localname.equalsIgnoreCase("Latitude")){
        double lat=Double.parseDouble(atts.getValue("lat"));
        sItem.setLatitude(lat);
        this.in_itemLatitude=true;
    }else if(localname.equalsIgnoreCase("Longitude")){
        double lon=Double.parseDouble(atts.getValue("lon"));
        sItem.setLatitude(lon);
        this.in_itemLongitude=true;
}
 list.add(sItem);

}

endElement method:

    @Override

    public void endElement(String namespaceURI, String localname, String qName)throws SAXException {
        if(localname.equalsIgnoreCase("Business")){
            this.in_business=false;
        }else if(localname.equalsIgnoreCase("local")){
            this.in_local=false;
        }else if(localname.equalsIgnoreCase("ItemName")){
            this.in_itemName=false;
        }else if(localname.equalsIgnoreCase("ItemAddress")){
            this.in_itemAddress=false;
        }else if(localname.equalsIgnoreCase("Latitude")){
            this.in_itemLatitude=false;
        }else if(localname.equalsIgnoreCase("Longitude")){
            this.in_itemLongitude=false;
        }   
}
    @Override
    public void characters(char ch[], int start, int length) {
                if(this.in_local){
                //currentCondition.(new String(ch, start, length));
               // sItem.equals(new String(ch,start,length));
        }
    }

The Activity:

    public class SearchItemListActivity extends ListActivity{
    String param="Bar";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_list);

    try {
        URL url = new URL("http://www.webitour.dk/service/localbusiness.aspx?cat="+param);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();

        /* Get the XMLReader of the SAXParser we created. */
        XMLReader xr = sp.getXMLReader();
        /* Create a new ContentHandler and apply it to the XML-Reader*/
        SearchItemHandler searchHandler=new SearchItemHandler();
        xr.setContentHandler(searchHandler);
        xr.parse(new InputSource(url.openStream()));
        SearchItem sItem=searchHandler.getParsedData();

        ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); 
        HashMap<String,String> item = new HashMap<String,String>();
        item.put("Name",sItem.getItemName());
        item.put("Address", sItem.getItemAddress());
        list.add(item);

        SimpleAdapter adapter = new SimpleAdapter(
                this,
                list,
                R.layout.custom_text_view,
                new String[] {"Name","Address"},
                new int[] {R.id.text1,R.id.text2}
                );

        setListAdapter(adapter);

    }catch(Exception e){
    }
}

}

SearchItem class:

    public class SearchItem {
    private String itemName;
    private String itemAddress;

    public SearchItem(){}

    public String getItemName(){
        return this.itemName;
    }
    public void setItemName(String itemName){
        this.itemName=itemName;
    }
    public String getItemAddress(){
        return this.itemAddress;
    }
    public void setItemAddress(String itemAddress){
        this.itemAddress=itemAddress;
    }

}
  • 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-05-20T02:26:56+00:00Added an answer on May 20, 2026 at 2:26 am

    I have read your code carefully then i have found you have done very serious mistake.

    By this code you have seen only last record in the list.

    Do this this i mention blow.

    1-:Create a class with variable
    public String Name,Address….

    2-:Create a list in SearchItemHandler Class.
    public static List=new List();
    then
    In the parsing of xml Your should create a Object of your ClassName(Create Above)
    and set the value of each data member of class by xml getValue
    then put this object in list.
    at the end of parsing you find three object in list .

    3-: Access this list in SearchItemListActivity class
    and fatch the value of each object and make a array adapter.

    4-:Put this adapter in list then you find three item in list.

    I hope this is help if you find any problem please right comment.

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

Sidebar

Related Questions

I m trying read XML data using XML parser from Url( https://....etc ). But
I am trying to read Ò ÉÑÎÔÜ Ê characters from XML and want to
I'm trying to prevent .NET Framework accessing the Web when validating an XML document
i have a windows app in vb.net , i am trying to read a
I need to consume a WCF service from a DLL, hence i don't have
Im trying to find a piece of software to help a small (~3-5 people)
My office uses a piece of software that generates XML based reports. These reports
Im trying to convert my WPF project to Silverlight. The WPF project was written
i'm italian, so, excuse me for my bad english. The problem is this.... I'm
I've got three DataTables that I need to join together, and use the joined

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.