我有以下Document对象 - Document myDoc。
myDoc通过...保存XML文件
myDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(file);
现在我想获取 XML 文件的根目录。有没有区别
Node firstChild = this.myDoc.getFirstChild()
和
Node firstChild = (Node)myDoc.getDocumentElement()
第一种方式,firstChild保存文件的节点根,XML但它的深度不为Node. 但是,在第二种方式中,firstChild将具有所有深度的根。
例如,我有以下 XML
<inventory>
<book num="b1">
</book>
<book num="b2">
</book>
<book num="b3">
</book>
</inventory>
并file持有它。
在第一种情况下,int count = firstChild.getChildNodes() 给出 count = 0.
第二种情况会给count = 3.
我对吗?