日期:2014-05-20 浏览次数:20719 次
private Map read(InputStream is) {
Map map = new HashMap();
try {
Document d = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(is);
Element root = d.getDocumentElement();
NodeList nList = root.getElementsByTagName("client");
String name, value = null;
for (int i = 0; i < nList.getLength(); i++) {
NodeList nList2 = nList.item(i).getChildNodes();
for (int j = 0; j < nList2.getLength(); j++) {
name = nList2.item(j).getNodeName();// /nList2:port,location,ip
if (!name.equals("#text")) {
if (d.getElementsByTagName(name).item(i)
.getFirstChild() != null) {
value = d.getElementsByTagName(name).item(i)
.getFirstChild().getNodeValue();
} else {
value = "";
}
map.put(name, value);
}
}
}
} catch (Exception e) {
}
return map;
}