Table of Contents

XMLnode Class

internal superclass of the XML classFlash 5 (undocumented)

Description

The XMLnode class defines the core properties and methods of nodes in an XML object hierarchy. Though XMLnode is internal to ActionScript, it can be used by programmers to add to the default functionality of XML objects.

Technically, every XML object hierarchy includes two kinds of object nodes:

The main container node is an instance of the XML class. For example, if we create myDoc as follows:

myDoc = new XML();

then myDoc is an instance of the XML class. The XML class inherits from the XMLnode class, so main container nodes have all the properties and methods defined by XMLnode plus those defined by XML. In contrast, the children of myDoc will actually be instances of the XMLnode class, not the XML class.

So, if we create myParagraph as follows:

myParagraph = myDoc.createElement("P");

then myParagraph is an instance of the XMLnode class. Most of the time, the internal distinction between node classes does not affect our use of XML objects. However, if we wish to add an inherited property or method to all XML objects, then we must use the XMLnode class's prototype, not the XML class's prototype (see the following Example). Any methods or properties attached to XMLnode.prototype are inherited by all XML nodes in a movie.

For reference, the properties, methods, and event handlers defined by XMLnode and XML are listed in Table 18-28. Note that while all listed items are accessible through instances of the XML class, items defined by XML are not available through instances of XMLnode. For example, the load( ) method can be invoked on an instance of the XML class, but not on an instance of the XMLnode class. For a full discussion of each item, see the appropriate XML class entry.

Table 18-28. XMLnode and XML properties, methods, and event handlers

XMLnode and XML

XML only

appendChild( )

contentType

attributes

createElement( )

childNodes

createTextNode( )

cloneNode( )

docTypeDecl

firstChild

getBytesTotal( )

hasChildNodes( )

getBytesLoaded( )

insertBefore( )

ignoreWhite

lastChild

load( )

nextSibling

loaded

nodeName

onData( )

nodeType

onLoad( )

nodeValue

parseXML( )

parentNode

send( )

previousSibling

sendAndLoad( )

removeNode( )

status

toString( )

xmlDecl

Example

The following code adds a custom secondChild( ) method to XMLnode.prototype (the secondChild( ) method is subsequently available from any XML node in our movie):

XMLnode.prototype.secondChild = function () {
  return this.childNodes[1];
};
   
myDoc = new XML("<PRODUCT>Cell Phone</PRODUCT><PRODUCT>Game Console</PRODUCT>");
   
trace(myDoc.secondChild());  // Displays: "<PRODUCT>Game Console</PRODUCT>"

It's also perfectly legitimate to augment the XML class via XML.prototype, but such additions apply only to main container nodes (direct instances of the XML class).

See Also

The XML class; "Superclasses and Subclasses," in Chapter 12


Table of Contents