To create the
XML fragment from Example 18-1 via E4X,
we have three general options:
Use the XML constructor to create a new XML instance, and then create the remainder of the fragment programmatically using the techniques covered in later section "Changing or Creating New XML Content."
Use the XML constructor to create a new XML instance, and then import the fragment from an externally loaded file, as discussed in the later section "Loading XML Data."
Write our XML data in literal form, just like a string or a number, anywhere literals are allowed by ActionScript.
For now, we'll use the third approach—creating the XML fragment
with an XML literal. Example 18-2 demonstrates; it
assigns a literal XML value (the XML fragment from Example 18-1) to the variable
Example 18-2. Assigning an XML literal to a variable
var novel:XML = <BOOK ISBN="0141182806"> <TITLE>Ulysses</TITLE> <AUTHOR>Joyce, James</AUTHOR> <PUBLISHER>Penguin Books Ltd</PUBLISHER> </BOOK>;
When the preceding code runs, ActionScript generates a new E4X
XML instance representing the
literal XML fragment and assigns it to the variable
To view the XML source code for an XML instance (such as the one referenced
novel), use the XML class's instance method toXMLString( ), as in:
The toXMLString( ) method is covered later in the section "Converting XML and XMLList to a String."
Notice that the line breaks and quotation marks in the preceding XML literal are ...