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
you can get attribute value like this: