
XML.getBytesLoaded() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
927
Description
The firstChild property is synonymous with childNodes[0]. It returns a reference to the
first node object that descends from
theNode, where theNode can be an XML or XMLnode
instance. If
theNode has no children, firstChild returns null.
In this XML source fragment, the
firstChild of the MESSAGE node is the text node with the
nodeValue “hey”:
<!-- Fragment 1 -->
<MESSAGE>hey</MESSAGE>
Here, the firstChild of the HOTEL node is the ROOM node:
<!-- Fragment 2 -->
<HOTEL><ROOM><SIZE>Double</SIZE></ROOM></HOTEL>
When theNode is the top of the object hierarchy (i.e., when it is an instance of the XML
class, which refers to an XML document object and not an instance of the XMLnode class),
firstChild may not always be a reference to the first useful element in the document. If a
document includes an XML declaration (
<?xml version="1.0"?>) and perhaps a DOCTYPE tag,
normally there are whitespace nodes before the actual root element of the XML hierarchy
(to remove them, use
XML.ignoreWhite). If an XML fragment has no XML declaration, no
DOCTYPE, and no whitespace, we can start processing it with the document’s firstChild
node, as in:
// Create a new XML fragment
myDoc = new XML('<MESSAGE><USER>gray</USER><CONTENT>hi</CONTENT></MESSAGE>'); ...