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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:18:12+00:00 2026-06-03T16:18:12+00:00

I want to parse an XML file using SAX parser in java with this

  • 0

I want to parse an XML file using SAX parser in java with this format :

<Deals>
  <Deal>
   <id> 10</id>
   <title> title </title>
   <city>
     <id> 1 </id>
     ...
   </city>
  </Deal>
  ...
</Deals>

I have a problem to distinguish between the id element of Deal Node and the id element of the city node.

  • 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-06-03T16:18:13+00:00Added an answer on June 3, 2026 at 4:18 pm

    One thing you can do (I’ve seen it around and used it — I’m not certain it’s the most efficient or effective way, but it works) is to maintain some state in your parser, whether that be a defined set of states, or some boolean flags, that describe where you are in the document. For example, you might have:

    boolean inDeals = false;
    boolean inDeal = false;
    boolean inCity = false;
    

    Then, in your startElement callback, if the start tag is Deals, set inDeals to true. Similarly for Deal and city. In the endElement callback, do the inverse (e.g. end tag == Deals, set inDeals back to false). In your characters method, or however you’re processing the tag, just handle based on the state of the parser at that time. For example:

    if(inDeal) {
        if(inCity) {
            cityId = /*the characters*/;
        } else dealId = /*the characters*/;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file in the drawable-folder. I want parse the XML-file using
I am using SAX Parser to parse the XML file over the network. While
I want to extract attributes from an xml file using Sax Parser I am
I have an XML file which is as follows. I want to parse this
I want to parse a large XML file and I have two options: Perl
I have some XML that I want to parse using the lxml method in
I have the following very simple XML file and I want to quickly parse
I'm using XML::Simple to parse an XML file which I then want to use
I want to parse an XML file using Perl . I was able to
I have an XML file which I want to convert into JSON file using

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.