Converting XML and XMLList to a String
As we've seen throughout this chapter, E4X implements custom rules for converting XML and XMLList instances to a string. For reference and review, this section describes E4X's XML-to-string and XMLList-to-string conversion rules. Remember that an XML instance can represent five different kinds of content: an element, an attribute, a text node, a comment, or a processing instruction. We'll consider the conversion rules for each kind separately, but we'll start with XMLList-to-string conversion in preparation for the subsequent discussion.
Converting XMLList to a String
When an XMLList has only
one XML instance, the result of
XMLList's toString( ) is exactly the same as the
result of calling toString( )
on that one instance. For example, in the following code, the
title variable refers to an
XMLList whose single XML instance represents the
<TITLE> element. Converting
title to a string yields
Ulysses, exactly as if toString( ) had been invoked on the
single XML instance
var novel:XML = <BOOK ISBN="0141182806"> <TITLE>Ulysses</TITLE> <AUTHOR>Joyce, James</AUTHOR> <PUBLISHER>Penguin Books Ltd</PUBLISHER> </BOOK> // Create an XMLList with only one XML instance var title:XMLList = novel.TITLE; // Convert the XMLList to a string, and display that string. trace(title); // Displays: Ulysses
When an XMLList has more than one XML instance, XMLList's toString( ) returns the result of calling toXMLstring( ) on each XML instance and concatenating those ...