안드로이드 개발 질문/답변
(글 수 45,052)
try{
URL text = new URL("http://www.google.co.kr/ig/api?weather=seoul");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(text.openStream(), "UTF-8");
int i = 0;
Log.d("여기", "2");
String condition = null;
String temp = null;
String wind = null;
while(parser.getEventType() != XmlPullParser.END_DOCUMENT) {
Log.d("여기", "3");
i = i + 3;
mProgressDialog.setProgress(i);
switch(parser.getEventType()) {
case XmlPullParser.START_DOCUMENT: // 문서의 시작
break;
case XmlPullParser.END_DOCUMENT: // 문서의 끝
break;
case XmlPullParser.TEXT:
break;
case XmlPullParser.START_TAG: // 시작 태그를 만나면 이름을 살펴봐서 작업(아무 일도 안하거나 값을 읽어 저장
Log.d("여기", "5");
if(parser.getName().equals("current_conditions")){
if(parser.getName().equals("condition")){
condition = parser.getAttributeValue(0);
}
if(parser.getName().equals("temp_c")){
temp = parser.getAttributeValue(0);
}
if(parser.getName().equals("wind_condtition")){
wind = parser.getAttributeValue(0);
}
WeatherData w1 = new WeatherData(condition, temp, wind);
m_weather.add(w1);
}
break;
}
parser.next();
}
mProgressDialog.setProgress(100);
handler.post(new Runnable() {
public void run() {
viewGo();
dismissDialog(DIALOG_PROGRESS);
mProgressDialog.dismiss();
}
});
} catch(Exception ex) {
}
}
<?xml version="1.0" ?> - <xml_api_reply version="1">
<city data="daegu" />
<postal_code data="daegu" />
<latitude_e6 data="" />
<longitude_e6 data="" />
<forecast_date data="2011-07-27" />
<current_date_time data="2011-07-27 01:59:28 +0000" />
<unit_system data="SI" />
</forecast_information>
<condition data="대체로 흐림" />
<temp_f data="88" />
<temp_c data="31" />
<humidity data="습도: 62%" />
<icon data="/ig/images/weather/mostly_cloudy.gif" />
<wind_condition data="바람: 남풍, 8 km/h" />
</current_conditions>
<day_of_week data="수" />
<low data="24" />
<high data="30" />
<icon data="/ig/images/weather/thunderstorm.gif" />
<condition data="강우(천둥, 번개 동반)" />
</forecast_conditions>
<day_of_week data="목" />
<low data="24" />
<high data="31" />
<icon data="/ig/images/weather/chance_of_storm.gif" />
<condition data="광역성 뇌우" />
</forecast_conditions>
<day_of_week data="금" />
<low data="24" />
<high data="31" />
<icon data="/ig/images/weather/chance_of_storm.gif" />
<condition data="광역성 뇌우" />
</forecast_conditions>
<day_of_week data="토" />
<low data="23" />
<high data="32" />
<icon data="/ig/images/weather/chance_of_storm.gif" />
<condition data="광역성 뇌우" />
</forecast_conditions>
</weather>
</xml_api_reply>
위에는 파싱하는 부분이고 밑에가 구글 날씨 api입니다.
current_condition 태그일때 밑에 있는 데이터를 가져오려고 하는데
뭐가 문제인지 안되네요;;




if(parser.getName().equals("current_conditions")){if(parser.getName().equals("condition")){
이름을 따서 들어갔는데 그라인에서 condition을 찾아봐야 나올리가 없죠. current_condition인데.
current_condition을 읽은 경우 따로 지정을 해서 다음 case에서 condition을 가져오게 해야죠.