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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:51:52+00:00 2026-06-04T13:51:52+00:00

I have a problem when parsing xml from the internet. The parser doesn’t return

  • 0

I have a problem when parsing xml from the internet. The parser doesn’t return all the data correctly.

Three are three errors:

correct result –>return result

161:1:161–>1:1:161

330:2:132–>3:2:132

421:2:223–>4:2:223

Copy of the xml file I am trying to parse

https://docs.google.com/open?id=0BwXEx9yI14inT1BnR2xzYnJEX0E

Activity

public class DataBaseUpdateService_1 extends Activity {
  private TextView TextView1 ;
  private LinearLayout linearlayout1 ;
  private TextView title[];
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_item);
    linearlayout1 = (LinearLayout)findViewById(R.id.linearlayout1);
    TextView1 = (TextView)findViewById(R.id.textView1);

    MyDBHelper dbHelper =new  MyDBHelper(DataBaseUpdateService_1.this);
    SQLiteDatabase db = dbHelper.getWritableDatabase();
      try {
      /** Handling XML */
      SAXParserFactory spf = SAXParserFactory.newInstance();
      SAXParser sp = spf.newSAXParser();
      XMLReader xr = sp.getXMLReader();

      /** Send URL to parse XML Tags */
      URL sourceUrl = new URL(
          "http://123.com/example.xml");

      /** Create handler to handle XML Tags ( extends DefaultHandler ) */
      DataBaseUpdate_XMLHandler XMLHandler = new DataBaseUpdate_XMLHandler();
      xr.setContentHandler(XMLHandler);
      xr.parse(new InputSource(sourceUrl.openStream()));

      }catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);
      }

      int itemCount =  DataBaseUpdate_XMLHandler.array.size();
      db.delete("hymns_match", null, null);

      try{  
        for(int i=0;i<itemCount;i++) {
          String songs_id=DataBaseUpdate_XMLHandler.array.get(i).get("songs_id");
          String songs_book_id=DataBaseUpdate_XMLHandler.array.get(i).get("songs_book_id");
          String songs_book_ch=DataBaseUpdate_XMLHandler.array.get(i).get("songs_book_ch");
          TextView tv = new TextView(DataBaseUpdateService_1.this);
          tv.setText(songs_id + ":"+songs_book_id+ ":"+songs_book_ch);
          linearlayout1.addView(tv);
        }
      }catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);
      }
  }
}

DataBaseUpdate_XMLHandler

public class DataBaseUpdate_XMLHandler extends DefaultHandler {
  Boolean currentElement = false;
  String currentValue=null;
  static ArrayList<LinkedHashMap<String, String>> array;
  LinkedHashMap map;

  @Override
  public void startDocument() throws SAXException {
    array = new ArrayList<LinkedHashMap<String, String>>();
  }

  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    currentElement = true;
    if (localName.equals("song")) {
      map = new LinkedHashMap<String, Object>();
      currentValue=null;
    } 
    /*Get attribute
     * else if (localName.equals("website")) {
     * String attr = attributes.getValue("category");
     * sitesList.setCategory(attr);}
     * */
  }

  @Override
  public void endElement(String uri, String localName, String qName) throws SAXException {
    currentElement = false;

    /** set value */ 
    if (localName.equalsIgnoreCase("songs_id")){
      map.put("songs_id",currentValue);}
    else if (localName.equalsIgnoreCase("songs_book_id")){
      map.put("songs_book_id", currentValue);}
    else if (localName.equalsIgnoreCase("songs_book_ch")){
      map.put("songs_book_ch", currentValue);}
    else if (localName.equalsIgnoreCase("song")){
      array.add(map);}
  }

  /** Called to get tag characters
  @Override
  public void characters(char[] ch, int start, int length) throws SAXException {
    if (currentElement) {
      currentValue = new String(ch, start, length);
      currentElement = false;
    }
  }
}

Can you give some advice about what’s wrong here?

  • 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-04T13:51:53+00:00Added an answer on June 4, 2026 at 1:51 pm

    According to the SAX definition characters() method can be called multiple times per elements. So it should accumulate the text; if this is happening then your code will not work.

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

Sidebar

Related Questions

I have this strange problem parsing XML document in PHP loaded via cURL. I
I have a problem with parsing html with JSoup The code is from a
I have problem in parsing XML containing gsm packets through my .Net application.I want
I am parsing an xml file from an API which I have converted into
I'm using the XML parsing methods from System.Xml.Linq . I've been ignoring this problem
i have a problem while building and running an iphone application.Im using xml parsing
I am currently scraping some data from the internet and converting into xml documents.
I have a problem that I am getting an xml file from raw resource
I need to insert data from my parsed XML file to mySQL table. Problem
Ok, I have a very frustrating problem. I am parsing a webpage and need

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.