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
  • 3 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 the output from the following code: int main(void) {
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble understanding the need for std::result_of in C++0x. If I understood
I have some trouble understanding this one so here it is. I'm trying to
I'm having some trouble understanding how codeigniters loading works. Well first you have the
I'm having some trouble understanding this issue. I have a class: class StringProperty {
it seems that I have some trouble understanding the semantics of the SUID bit,
I'm using Bison to create a simple parser and have some trouble understanding the
I'm having trouble understanding some concepts. In the Unicode spec, there's a property called
I have real trouble understanding mod_rewrite, and got some help in creating a RewriteRule

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.