package com.bingsudevil.classes;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import com.bingsudevil.dto.ItemInfoDto;
import android.util.Log;
public class ItemDataLoad extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
try{
URL url = new URL("http://www.wizcompany.com/gbid/app/itemxml/itemsinfo.xml");
HttpURLConnection httpcon = (HttpURLConnection)url.openConnection();
if(httpcon != null){
httpcon.setDoInput(true);
httpcon.setConnectTimeout(1000);
if(httpcon.getResponseCode() == HttpURLConnection.HTTP_OK){
InputStreamReader is = new InputStreamReader(httpcon.getInputStream(),"EUC-KR");
BufferedReader br = new BufferedReader(is);
String strxml ="";
StringBuffer sb = new StringBuffer();
while((strxml = br.readLine()) != null){
sb.append(strxml);
}
xmlparse(sb.toString());
}
}
}catch (Exception e) {
// TODO: handle exception
}
}
private void xmlparse(String strxml){
try{
ArrayList<ItemInfoDto> datalist;
ItemInfoDto dto;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document root = parser.parse(new InputSource(new StringReader(strxml)));
NodeList node = (NodeList) root.getElementsByTagName("items");
for(int i=0; i < node.getLength(); i++){
Log.d("--", node.item(i).getChildNodes().item(1).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(3).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(5).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(7).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(9).getTextContent());
}
}catch (Exception e) {
// TODO: handle exception
}
}
}
class부분이구요;;
<info>
<items>
<type>coffeebingsu</type>
<itemname>커피빙수</itemname>
<itemprice>15000원</itemprice>
<itemcontent>커피랑 빙수를 섞었습니다.</itemcontent>
<imagepath>http://www.wizcompany.com/gbid/app/images/coffeebingsu.jpg</imagepath>
</items>
<items>
<type>berrybingsu</type>
<itemname>딸기빙수</itemname>
<itemprice>10000원</itemprice>
<itemcontent>딸기랑 빙수를 섞었습니다.</itemcontent>
<imagepath>http://www.wizcompany.com/gbid/app/images/berrybingsu.jpg</imagepath>
</items>
</info>
xml 인데요;;
Log.d("--", node.item(i).getChildNodes().item(1).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(3).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(5).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(7).getTextContent());
Log.d("--", node.item(i).getChildNodes().item(9).getTextContent());
이 부분에서요 ; 제 생각대로라면;;
node.item(i).getChildNodes().item(0)
node.item(i).getChildNodes().item(1)
node.item(i).getChildNodes().item(2)
node.item(i).getChildNodes().item(3)
node.item(i).getChildNodes().item(4)
node.item(i).getChildNodes().item(5)
이렇게 해야;; 값이나오는게 정상아닌가요??
제가 뭘잘못햇는지;;;; 홀수 2개씩 하니까 값이 잘나오네요 --;;;;
이거 제가 뭘모르는게 잇는건가요?? 고수님들 도와주세요 ㅠㅠ..;;