different between “getDocumentElement” and “getFirstChild”

waniisops

New Member
I have the following \[code\]Document\[/code\] object - \[code\]Document myDoc\[/code\].\[code\]myDoc\[/code\] holds an \[code\]XML\[/code\] file by...\[code\]myDoc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(file);\[/code\]Now I want to get the root of the XML file. Is there any difference between \[code\]Node firstChild = this.myDoc.getFirstChild() \[/code\]and\[code\]Node firstChild = (Node)myDoc.getDocumentElement()\[/code\]In the first way, \[code\]firstChild\[/code\] holds a node root of an \[code\]XML\[/code\] file but it will not have the depth of \[code\]Node\[/code\]. However, in the second way, \[code\]firstChild\[/code\] will be the root with all of the depth.For example, I have the following XML\[code\]<inventory> <book num="b1"> </book> <book num="b2"> </book> <book num="b3"> </book></inventory>\[/code\]and \[code\]file\[/code\] holds it.In the 1st case, \[code\]int count = firstChild.getChildNodes()\[/code\] gives \[code\]count = 0\[/code\]. The 2nd case will give \[code\]count = 3\[/code\].Am I right?
 
Back
Top