我正在尝试通过将所有“< Type>”来从URL解析XML文件。参数type_id =“4218”的元素?
XML文档:
Football Matches
...
...
...
...
...
...
...
这是我的Java代码:
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new URL("/cubs/cubs.php?action=getpage&thepage=385.xml").openStream());
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("Type");
System.out.println("ukupno:"+nodeList.getLength());
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
Element el = (org.w3c.dom.Element) nodeList.item(j);
type_id = Integer.parseInt(el.getAttribute("type_id"));
System.out.println("type id:"+type_id);
}
}
这个代码给我所有的元素,我不想要,我想要所有元素的属性type_id =“4218”!