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

The Archive Base Latest Questions

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

I’m trying to parse some of my first XML documents in SAX by simply

  • 0

I’m trying to parse some of my first XML documents in SAX by simply implementing org.xml.sax.ContentHandler, and I don’t know if I’m understanding the flow. For a given XML document:

<?xml version="1.0"?>
<list>
    <item>
        <name>One</name>
        <description>The number 1, expressed in letters.
    </item>
    <item>
        <name>Two</name>
        <description>The number 2, expressed in letters.
    </item>
</list>

What would be the expected order of events in the parser? Am I right in assuming the following:

startDocument()
    startElement() -> "list"

        startElement() -> "item"
            startElement() -> "name"
                characters() (>=1 times) -> "One"
            endElement() -> "name"
            startElement() -> "description"
                characters() (>=1 times) -> "The number 1, expressed in letters."
            endElement() -> "description"
        endElement() -> "item"

        startElement() -> "item"
            startElement() -> "name"
                characters() (>=1 times) -> "Two"
            endElement() -> "name"
            startElement() -> "description"
                characters() (>=1 times) -> "The number 2, expressed in letters."
            endElement() -> "description"
        endElement() -> "item"

    endElement() -> "list"
endDocument()

Is that pretty much the gist of it?

Also, what’s the easiest way to parse? Presently, at each call to startElement, I’m saving as a private variable the name of the current element for when I’m parsing data in the characters call. Is there an easier/better way of doing it?

  • 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-23T18:56:29+00:00Added an answer on May 23, 2026 at 6:56 pm

    Yes, you’ve got the gist of it.

    SAX is a very low-level interface so don’t expect it to be easy. In most SAX applications you will probably want to maintain a stack, where startElement pushes the element name onto the stack, and endElement pops it off. If you’re not handling mixed content, then characters() should probably append to a StringBuffer associated with the element on the top of the stack, and you should process the character content in the StringBuffer when the endElement event occurs. That’s because character content can be split into multiple calls on characters() any way the parser wants.

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

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.