package com.example.test;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import javax.xml.datatype.Duration;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Document doc = null;
ArrayList<WeatherVO> list; //현재지역 모든값 저장.
Intent i;
TextView tv1;
String busan;
HashMap<String,HashMap<String,String>> resultList = new HashMap<String,HashMap<String,String>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tv1);
try{
setXml();
}catch(Exception e){
}
tv1.setText(busan);
}
public void setXml() throws ParserConfigurationException, SAXException,IOException{
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder =factory.newDocumentBuilder();
Document doc = builder.parse("http://www.kma.go.kr/XML/weather/sfc_web_map.xml");
NodeList local = doc.getElementsByTagName("local");
if(local.getLength() > 0){
String nodeValue = null;
HashMap<String,String> itemMap = null;
for(int i = 0; i < local.getLength();i++){
Element e = (Element) local.item(i);
nodeValue = e.getFirstChild().getNodeValue();
itemMap = new HashMap<String,String>();
itemMap.put("아이콘넘버", e.getAttribute("icon"));
itemMap.put("날씨", e.getAttribute("desc"));
itemMap.put("기온", e.getAttribute("ta"));
if(nodeValue != null&&itemMap !=null){
resultList.put(nodeValue, itemMap);
}
}
busan=resultList.get("부산").get("날씨").toString();
} // if local.getLength() end
}catch(Exception e){}
}
}
xml파싱할려고 하는데 자바로되어있는걸 안드로이드로 이런식으로 바꿨는데 안되네요 무엇이 잘못일까요 ㅠㅠ