我有一个xml文件,如下所示.我想要得到药店节点的纬度和经度属性.我可以获得chilnodes属性,但不能得到根节点属性.我是新的
java和xml.我找不到解决方案如何做.
这是我的代码部分.我从一个URL地址获取xml文件.
DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList =doc.getElementsByTagName("pharmacy");
for (int i = 0; i < nodeList.getLength(); i++){
Node node =nodeList.item(i);
Element fstElmnt = (Element) node;
NodeList pharmacyList = fstElmnt.getElementsByTagName("pharmacy");
Element pharmacyElement = (Element) pharmacyList.item(0);
Element pharmacyElement = (Element) pharmacyList.item(0);
HashMapmap=new HashMap();
map.put("name",pharmacyElement.getAttribute("name"));
map.put("distance",pharmacyElement.getAttribute("phone"));
list.add(map);
latt.add(pharmacyElement.getAttribute("lat"));
....