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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:14:34+00:00 2026-05-25T15:14:34+00:00

Using SAX parser in Java, how to do attribute based parsing. Suppose my xml

  • 0

Using SAX parser in Java, how to do attribute based parsing.

Suppose my xml file is as follows,

 <?xml version="1.0" encoding="UTF-8"?>
<employees category="1" type="regular" location="india">
    <employee name="xyz" doj="20/12/2001" dob="21/12/1988" salary="12000"></employee>
    <employee name="xyz" doj="22/12/2003" dob="22/12/1988" salary="18000"></employee>
    <employee name="xyz" doj="23/12/2002" dob="23/12/1988" salary="15000"></employee>
    <employee name="xyz" doj="24/12/2003" dob="22/12/1988" salary="17000"></employee>
    <employee name="xyz" doj="26/12/2005" dob="24/12/1988" salary="12000"></employee>

</employees>

I want to fetch the each attribute values of employee element. Please help me out

  • 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-25T15:14:35+00:00Added an answer on May 25, 2026 at 3:14 pm

    The DefaultHandler class provides a callback to listen for start elements, and it has a signature that contains an Attributes object, representing the attributes of that element.

    startElement(String uri, String localName, String qName, Attributes attributes)

    Looking at the Attributes interface, I see methods to help you out.

    1. If you don’t know which attributes you are interested in, and you want to look at all attributes, you should use getLength(), and the do a for-loop over that length, looking at each attributes getLocalName(int) or getQName(int), and you can find its value by calling getValue(int) (all int‘s are used as indices into the attributes list).
    2. If you do know which attributes you are interested in, you can simply call getValue(String), passing in the string name of the attribute you are after.

    Here is some example code that could get you the names and values of all attributes of a given element:

    public void startElement(String ns, String localName, String qName, Attributes attrs) throws SAXException {
        for(int i = 0; i < attrs.getLength(); ++i) {
            String attrName = attrs.getLocalName(i);
            String attrValue = attrs.getValue(i);
    
            //do stuff with name/value
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi friends i'm using Sax parser for parsing my xml file which i recieve
Parsing an XML file using the Java DOM parser results in: [Fatal Error] os__flag_8c.xml:103:135:
I have a problem with using the SAX parser to parse a XML file.
I have to parse a XML structure in JAVA using the SAX parser. The
When i try to read the xml from java using SAX parser, it is
I want to extract attributes from an xml file using Sax Parser I am
I am trying to split a large XML file into smaller files using java's
I am using SAX to parse XML files. Let's suppose that I want my
I am using SAX parser to parse a XML response but it throws an
I have two applications written in Java that communicate with each other using XML

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.