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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:17:07+00:00 2026-06-16T20:17:07+00:00

Im trying to identify an attribute using SAX. My XML is as follows <DAY

  • 0

Im trying to identify an attribute using SAX. My XML is as follows

<DAY VALUE="1">
    <BREAKFAST>0700</BREAKFAST>
    <LUNCH>1200</LUNCH>
    <DINNER>1900</DINNER>
</DAY> 
<DAY VALUE="2">
    <BREAKFAST>0730</BREAKFAST>
    <LUNCH>1230</LUNCH>
    <DINNER>1930</DINNER>
</DAY> 

and my startElement code is as follows:

@Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        elementOn = true;
        if (localName.equals("DAY"))
        {
            data = new XMLGettersSetters();
        } 
    }

The above code will find the first element "DAY" and give me the contents but not the remaining DAY elements.

Is there a way I can search for the attribute? I am aiming to get the current day in the month and then search for the day within the xml. For example if today is the 2nd then I want to search in the XML file for DAY VALUE="2" and get the sub elements

==EDIT

If i modify my XML to

<DAY_1>
        <BREAKFAST>0700</BREAKFAST>
        <LUNCH>1200</LUNCH>
        <DINNER>1900</DINNER>
    </DAY_1> 
    <DAY_2>
        <BREAKFAST>0730</BREAKFAST>
        <LUNCH>1230</LUNCH>
        <DINNER>1930</DINNER>
    </DAY_2>

and code to:

  if (localName.equals("DAY_2"))
        {
            data = new XMLGettersSetters();
        } 

I get a NullPointerException however the name if the class is not highlighted in logcat. It was referring to another class but i commented out those lines

  • 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-16T20:17:08+00:00Added an answer on June 16, 2026 at 8:17 pm

    you can get attribute value like this:

     if (localName.equals("DAY")){
        String day = "";
        if (attributes.getValue("VALUE") != null) {
            day = attributes.getValue("VALUE");
        }
                    //data = new XMLGettersSetters();
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to identify duplicate serial numbers from the following xml using XPath
Using Delphi XE 2 I've trying to identify the zoom direction to apply the
I am trying to identify a device using ATA_PASS_THROUGH_EX. When I see the output
I am trying to process an XML file using only Linux CLI tools. The
I'm trying to create a xml using xslt. This is the xml that is
I'm trying to identify if this is an IIS issue or a code issue.
I am trying to identify when an action without authorization has been made. Is
I am trying to identify a screen in a multi-monitor setup to save some
I am trying to identify file types for directory entries (Windows Unix etc..). In
I am trying to identify all the nodes in a tree that lead 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.