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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:30:31+00:00 2026-05-18T20:30:31+00:00

I’m using SAX parser in my Android application to read a few feeds a

  • 0

I’m using SAX parser in my Android application to read a few feeds a time. The script is executed as follows.

                     // Begin FeedLezer
                    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(
                            BronFeeds[i]);

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

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

                    String titels = sitesList.getMergedTitles();

And here are Feed_XMLHandler.java and Feed_XMLList.java, which I basically both just took from the web.

However, this code fails at times. I’ll show some examples.

http://imm.io/media/2I/2IAs.jpg
It goes very well here. It even recognizes and displays apostrophes. Even when clicking the articles open, almost all of the text shows, so that’s all good. The source feed is here. I can’t control the feed.

http://imm.io/media/2I/2IB1.jpg Here, it doesn’t go so well. It does display the ï, but it chokes on the apostrophe (there’s supposed to be ‘NORAD’ after the Waarom). Here

http://imm.io/media/2I/2IBQ.jpg This is the worst one. As you can see, the title only displays an apostrophe, whilst it is supposed to be a ‘blablabla’. Also, the text ends in the middle of the line, without any special characters in the quote. The feed is here

In all cases, I have no control over the feed. I think the script does choke on special characters. How can I make sure SAX fetches all the strings correctly?

If anyone knows an answer to this, you really help me out a LOT 😀

Thanks in advance.

  • 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-18T20:30:32+00:00Added an answer on May 18, 2026 at 8:30 pm

    This is from the FAQ of Xerces.

    Why does the SAX parser lose some
    character data or why is the data
    split into several chunks? If you
    read the SAX documentation, you will
    find that SAX may deliver contiguous
    text as multiple calls to characters,
    for reasons having to do with parser
    efficiency and input buffering. It is
    the programmer’s responsibility to
    deal with that appropriately, e.g. by
    accumulating text until the next
    non-characters event.

    You’re code is very well adapted from one of many XML Parsing tutorials (like this one here) Now, the tutorial is good and all, but they fail to mention something very important…

    Notice this part here…

        public void characters(char[] ch, int start, int length)
                throws SAXException
        {
                  if(in_ThisTag){
                         myobj.setName(new String(ch,start,length))
                  }
        }
    

    I bet at this point you’re checking up booleans to mark which tag you’re under and then setting a value in some kind of class you made? or something like that….

    But the problem is, the SAX parser (which is buffered) will not necesarily get you all the characters between a tag at one go….say if <tag> Lorem Ipsum...really long sentence...</tag> so your SAX parser calls characters function is chunks….

    So the trick here, is to keep appending the values to a string variable and the actually set (or commit) it to your structure when the tag ends…(ie in endElement)

    Example

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
    
        currentElement = false;
    
        /** set value */
        if (localName.equalsIgnoreCase("tag"))
                {
            sitesList.setName(currentValue);
                        currentValue = ""; //reset the currentValue
                }
    
    }
    
    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
    
        if (in_Tag) {
            currentValue += new String(ch, start, length); //keep appending string, don't set it right here....maybe there's more to come.
        }
    
    }
    

    Also, it would be better if you use StringBuilder for the appending, since that’ll be more efficient….

    Hope it makes sense! If it didn’t check this and here

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but

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.