안녕하세요. 도와주세요
XML 파서를 사용해서 내용을 가져올때..
아래 내용을 가저와서 읽으면...
<title><strong>화성</strong>에도 생명체가? 지구와 같은 생태계??</title>
이렇게만 저장이 됩니다. <
< 값만 읽고 끝나버리는데.. 전부 읽으려면. 어떻게 해야할가요?
그냥 글씨만 읽으면 다 읽어와 지는데..
ㅠㅠ
public HashMap<String, String> xml2HashMap(String tmpData, String encoding) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("count", "0");
try {
DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
DocumentBuilder docB = docBF.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(tmpData.getBytes(encoding));
Document doc = docB.parse(is);
Element lists = doc.getDocumentElement();
NodeList dataList = lists.getElementsByTagName("item");
int c = 0;
for (int i = 0; i < dataList.getLength(); i++) {
NodeList dataNodeList = dataList.item(i).getChildNodes();
for (int j = 0; j < dataNodeList.getLength(); j++) {
;
Node itemNode = dataNodeList.item(j);
if (itemNode.getFirstChild() != null) {
String nodeName = itemNode.getNodeName();
String nodeValue = itemNode.getFirstChild().getNodeValue();
hm.put(nodeName + "[" + i + "]", nodeValue);
Log.v(nodeName, nodeValue);
}
}// for j
c++;
}// for i
hm.put("count", Integer.toString(c));
} catch (Exception e) {
Log.e("util.xml2HashMap", e.getMessage());
}
return hm;
}