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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:32:27+00:00 2026-05-18T05:32:27+00:00

I have some trouble understanding parsing XML structures with SAX. Let’s say there is

  • 0

I have some trouble understanding parsing XML structures with SAX. Let’s say there is the following XML:

<root>
  <element1>Value1</element1>
  <element2>Value2</element2>
</root>

and a String variable myString.

Just going through with the methods startElement, endElement() and characters() is easy. But I don’t understand how I can achieve the following:

If the current element equals element1 store its value value1 in myString. As far as I understand there is nothing like:

if (qName.equals("element1")) myString = qName.getValue();

Guess I’m just thinking too complicated 🙂

Robert

  • 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-18T05:32:28+00:00Added an answer on May 18, 2026 at 5:32 am

    With SAX you need to maintain your own stack. You can do something like this for very basic processing:

    void startElement(...) {
        if (name.equals("element1")) {
            inElement1 = true;
            element1Content = new StringBuffer();
        }
    }
    
    void characters(...) {
        if (inElement1) {
            element1Content.append(characterData);
        }
    }
    
    void endElement(...) {
        if (name.equals("element2")) {
            inElement1 = false;
            processElement1Content(element1Content.toString());
        }
    }
    

    If you want code as in your example then you need to use the DOM model rather than SAX. DOM is easier to code up but is generally slower and more memory expensive than SAX.

    I recommend using a third-party library rather than the built-in Java XML libraries for DOM manipulation. Dom4J seems pretty good but there are probably other libraries out there too.

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

Sidebar

Related Questions

I have some trouble understanding this one so here it is. I'm trying to
I have some trouble understanding the need for std::result_of in C++0x. If I understood
I'm having some trouble understanding Outlook terms (CommandBarPopup, CommandBarButton etc) like what is what
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
I am currently switching from AS3 to JavaScript. I still have some trouble with
I am having some trouble understanding the MVC Pattern. I do understand we are
I am having some trouble understanding how to make System Sequence Diagrams, as I
I'm trying out some MacOS programming and having some trouble understanding how bindings work
first I want to say that I hope this doesn't look like I am
The title tells it all, I need to see how others solve this to

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.