'초간단 xml 파싱'에 해당되는 글 1건

  1. 2012.01.27 초간단 xml 파싱
반응형
String t_xmlStr =           
   "<root>" +           
   "<item value=\"돈까스\">" +
   "<item value=\"순대국\">" +
   "<item value=\"짜장면\">" +
   "</item></item></item></root>";
   
  DocumentBuilderFactory t_dbf = null;       
  DocumentBuilder t_db = null;       
  Document t_doc = null;       
  NodeList t_nodes = null;       
  Node t_node = null;       
  Element t_element = null;       
  InputSource t_is = new InputSource();        
  try{           
   t_dbf = DocumentBuilderFactory.newInstance();           
   t_db = t_dbf.newDocumentBuilder();           
   t_is = new InputSource();           
   t_is.setCharacterStream(new StringReader(t_xmlStr));           
   t_doc = (Document) t_db.parse(t_is);           
   t_nodes = t_doc.getElementsByTagName("item");            
   for (int i = 0, t_len = t_nodes.getLength(); i < t_len; i ++){              
    t_element = (Element)t_nodes.item(i);                
    System.out.println(t_element.getAttribute("value"));   
    collection.add(new personVO(t_element.getAttribute("value"), t_element.getAttribute("value"), t_element.getAttribute("value")));
   }       
  }catch (Exception e){           
   e.printStackTrace();       
  }
Posted by 1010