我有一个xml,如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bookshelf>
<book ISBN="a01" press="AD press"/>
<book ISBN="a11" press="BC press">
<book>JavaSE</book>
<Author>John</Author>
<price>35.00</price>
</book>
<book ISBN="b11" press="XY press">
<book>Android</book>
<Author>Smith</Author>
<price>35.00</price>
</book>
</bookshelf>
下面是一个简单的Java dom程序:
System.out.println(currentPath);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(currentPath + "/book.xml");
Node node = document.getElementsByTagName("").item(1);
System.out.println(node);
(1( 它打印出"null",为什么?
(2( 我在谷歌上搜索了很多示例代码来调用document.getElementsByTagName("(,我想知道"是代表根元素还是其他什么?
非常感谢。
(1(它打印出"null",为什么?标记名称("(为空。请提供任何合适的标签名称("书"(包括在给定的xml文件
(2( 以获取根元素的名称。这是根元素的返回名称
document.getDocumentElement().getNodeName();