代码
Element n1 = (Element) books.item(i);
System.out.println(n1.getAttribute("id"));
直接把Node对象强转Element对象集合,Element和Node是继承关系,所以强转也可以正常使用,还可以使用Element独有的
getAttribute(String name)的方法
本文介绍了一种在Java中从XML文档的Node对象转换为Element对象的方法,并展示了如何使用Element对象特有的getAttribute方法来读取属性值。
Element n1 = (Element) books.item(i);
System.out.println(n1.getAttribute("id"));
直接把Node对象强转Element对象集合,Element和Node是继承关系,所以强转也可以正常使用,还可以使用Element独有的
getAttribute(String name)的方法
1898
1455
959
880

被折叠的 条评论
为什么被折叠?
