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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:23:07+00:00 2026-05-13T18:23:07+00:00

I am parsing xml using the SAXParser and want to know if this is

  • 0

I am parsing xml using the SAXParser and want to know if this is the right way to implement the characters method.

Assume there’s a class-level String variable named elementValue and it is initialized to “” in the startElement method.

Here is the characters method:

@Override
public void characters(char[] ch, int start, int length)
{
    String charsToAppend = new String(ch, start, length);
    elementValue = elementValue + charsToAppend;    
}

Is it correct that we need to append to the value we have so far and is the append being done correctly?

Also, why does the characters method give the start index? Won’t it be zero every time?

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-05-13T18:23:07+00:00Added an answer on May 13, 2026 at 6:23 pm

    Yes, you need to append because there is no guarantee that the chunk of data read will contain all of the element text.

    The start position is given and needs to be used because the other characters in the array can be junk.

    However, you should use a StringBuffer instead, and call its’ append() method, like so:

    public void characters(char[] ch, int start, int length) {
      yourStringBuffer.append(ch, start, length);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems parsing this piece of XML using SimpleXML. There is
I am parsing XML Document using SAX Parser. I want to know which is
I have student.xml file and am parsing this file using SAX Parser and now
this is my first time using StAX for parsing XML documents (still in the
I am parsing some XML using Nokogiri and XPath. When I do this: doc.xpath('//Order/child::node()').each
I'm having trouble parsing this xml file using jquery: <?xml version=1.0 encoding=utf-8?> <?mso-infoPathSolution name=urn:schemas-microsoft-com:office:infopath:BOT-Memos:-myXSD-2011-07-13T14-29-57
I am using SaxParser for parsing a XML which contains some image url which
I have done one program in android using xml parsing but there is an
Is there any way of parsing an XML file without knowing the tags present
Thanks for previous replies. I am parsing XML file using java(SAXParser), i am not

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.