Ho il seguente oggetto Document
- Document myDoc
.diversi tra "getDocumentElement" e "getFirstChild"
myDoc
detiene un file XML
da ...
myDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(file);
Ora voglio ottenere il root del file XML. C'è qualche differenza tra
Node firstChild = this.myDoc.getFirstChild()
e
Node firstChild = (Node)myDoc.getDocumentElement()
Nel primo modo, firstChild
detiene una radice il nodo di un file XML
ma non avrà la profondità di Node
. Tuttavia, nel secondo modo, firstChild
sarà la radice con tutta la profondità.
Per esempio, ho il seguente XML
<inventory>
<book num="b1">
</book>
<book num="b2">
</book>
<book num="b3">
</book>
</inventory>
e file
lo tiene.
Nel primo caso, int count = firstChild.getChildNodes()
corrisponde a count = 0
.
Il secondo caso darà count = 3
.
Ho ragione?
ahh quindi il commento ha portato al diff erence .. wow grazie! – URL87