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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:08:40+00:00 2026-05-15T17:08:40+00:00

I have a SAXParser with with an XMLReader. SAXParserFactory saxPF = SAXParserFactory.newInstance(); SAXParser sp

  • 0

I have a SAXParser with with an XMLReader.

SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser sp = saxPF .newSAXParser();
XMLReader xmlR = sp.getXMLReader();
MyHandler myHandler = new MyHandler();
xmlR .setContentHandler(myHandler );

My handler code uses startElement and endElement to detect with it’s inside a tag. It does this by setting a boolean and using characters() to grab the value

public void startElement(String namespaceURI, 
    String localName, String qName, Attributes atts) throws SAXException {
    if (localName.equals("myTag")) this.in_myTag = true;
}

public void characters(char ch[], int start, int length) {
            if(in_myTag )  { c.setMyTag(new String(ch, start, length));
}

The problem is that I have a tag that is “A & B Value” and it’s notifying characters() for “A” and “&” and “B” and “Value”. So the final value of setMyTag is “Value”

<myTag>A & B value</myTag>

http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html

  • 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-15T17:08:42+00:00Added an answer on May 15, 2026 at 5:08 pm
    <myTag>A & B value</myTag>
    

    (That’s not XML. I assume you mean A &amp; B value, to be well-formed.)

    In general you can’t guarantee that your characters() handler will get called exactly once per element. If there is no text content in the element it won’t get called at all; if there are entity references or the text is very long you are likely to get called more than once. Plus of course any comments, PIs or other elements in there will definitely need multiple calls.

    Whilst it is unusual for a predefined entity reference like &amp; to cause a separate callback to the content handler, there’s nothing in the spec to say it can’t happen at any time for any (or no) reason. In particular:

    SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks

    Consequently, a SAX handler must collect every piece of text content sent to it and join them together when endElement occurs, rather than setting the content from a single characters callback.

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

Sidebar

Ask A Question

Stats

  • Questions 480k
  • Answers 480k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably want to use the String2D class (the String… May 16, 2026 at 6:04 am
  • Editorial Team
    Editorial Team added an answer You need to change the constructor of the second form… May 16, 2026 at 6:03 am
  • Editorial Team
    Editorial Team added an answer It's difficult to do this without passing a context through… May 16, 2026 at 6:03 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.