마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

xml파싱 소스를 만드었는데 안되는 무엇이 문제일까요 ㅠㅠ

0 추천
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파싱할려고 하는데 자바로되어있는걸 안드로이드로 이런식으로 바꿨는데 안되네요 무엇이 잘못일까요 ㅠㅠ 

maechanisgod (210 포인트) 님이 2014년 11월 14일 질문

1개의 답변

0 추천
 
채택된 답변
  1. network 작업을 DocumentBuilder  가 알아서 해주나요?
  2. 안드로이드는 network 작업을 반드시 thread 내에서 처리해야 합니다.
aucd29 (218,390 포인트) 님이 2014년 11월 14일 답변
maechanisgod님이 2014년 11월 14일 채택됨
...