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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:03:10+00:00 2026-05-26T06:03:10+00:00

I write application which will be parse XML files. I use SAX parser and

  • 0

I write application which will be parse XML files. I use SAX parser and here is my SAX handler code:

public class XMLHandler extends DefaultHandler {

private static final String MEASURES = "measures";

private static final String SUGARMEASUREDATE = "sugarMeasureDate";
private static final String SUGARMEASUREVALUE = "sugarMeasureValue";

private static final String UPGYROSCOPEDATE = "upGyroscopeDate";
private static final String UPGYROSCOPEVALUE = "upGyroscopeValue";

private static final String DOWNGYROSCOPEDATE = "downGyroscopeDate";
private static final String DOWNGYROSCOPEVALUE = "downGyroscopeValue";

Boolean currentElement = false;
String currentValue = null;

public static MeasureLists measureLists = null;

public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    currentElement = true;

    if (localName.equals("measures")) {
        measureLists = new MeasureLists();
    }
}

public void endElement(String uri, String localName, String qName) throws SAXException {

    currentElement = false;
    if (localName.equals(SUGARMEASUREDATE)) {
        measureLists.setSugarDate(currentValue);
    }
    else if (localName.equals(SUGARMEASUREVALUE)) {
        measureLists.setSugarValue(currentValue);
    }
    else if (localName.equals(UPGYROSCOPEDATE)) {
        measureLists.setUpGyroscopeDate(currentValue);
    }
    else if (localName.equals(UPGYROSCOPEVALUE)) {
        measureLists.setUpGyroscopeValue(currentValue);
    }
    else if (localName.equals(DOWNGYROSCOPEDATE)) {
        measureLists.setDownGyroscopeDate(currentValue);
    }
    else if (localName.equals(DOWNGYROSCOPEVALUE)) {
        measureLists.setDownGyroscopeValue(currentValue);
    }
}

public void characters(char[] ch, int start, int length) throws SAXException {

    if (currentElement) {
        currentValue = new String(ch, start, length);
        currentElement = false;
    }
}

public MeasureLists getMeasureLists() {
    return measureLists;
}
}

My problem is that this code detects events (start and end tag) properly but variable localName is empty String. I read in documentation that localName is empty if “Namespace processing is not being performed.” My question is what it is mean and how can I handle with it. Thanks for any help and tip.

EDIT

I notice that when I change “localName” variable for “qName” there all things go right and I have no problem. Do you know what it is?

  • 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-26T06:03:11+00:00Added an answer on May 26, 2026 at 6:03 am

    My guess is that your XML uses namespaces, but your SAXParser is not configured for namespace processing (in which case the qualified element, ‘prefix:localName’, is present in the qName parameter). If you use JAXP, set the namespaceAware property on the SAXParserFactory to true. To be really sure that your’e processing the correct elements, you should also check that the uri parameter is what you expect (or should expect).

    You also have a problems with the characters method. The caharacters() method may be called more than once for each element, even if the element contain only text. What you need to do is to use a StringBuidler to collect the characters in, and use that in the enedELement method.

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

Sidebar

Related Questions

I wrote a RSS based application that will fetch some XML files, parse them
I've been trying to write a small application which will work with mysql in
I'm trying to write a small wsgi application which will put some objects to
I need to write a standalone Java application which will have a embedded HTTP
I am attempting to write a VB.net application which will allow users to create
I need to write a java application which can merge docx files. Any suggestions?
I would like to write application which will iterate trough certain test cases and
I would like to write an application which will stream data at 2400 baud
I need to write some application which will have a couple threads and these
I have to write VXML application which will be able to access to database.

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.