I need to extract the value from "condition" but the one that's under "current_conditions".

Here is the code I have right now. It extracts value from condition but from "forecast_conditions". By the way i'm using SAXParser.

if (localName.equals("condition")) {

String con = attributes.getValue("data");

info.setCondition(con);

}

Here is the XML.

<current_conditions>

<condition data="Clear"/>

</current_conditions>

<forecast_conditions>

<condition data="Partly Sunny"/>

</forecast_conditions>

网友答案:

Which parser do you use? If you use XmlPullParser (or any SAX style parser), you can set a flag when you encounter current_conditions START_TAG and check whether this flag is set when you check for condition. Don't forget to reset the flag when you encounter current_conditions END_TAG.