The
XML and XMLList classes include a
toString()
method
and a
toXMLString()
method. The
toXMLString()
method
returns a string that includes all tags, attributes, namespace declarations,
and content of the XML object. For XML objects with complex content
(child elements), the
toString()
method does exactly
the same as the
toXMLString()
method. For XML objects
with simple content (those that contain only one text element),
the
toString()
method returns only the text content
of the element, as the following example shows:
var myXML:XML =
<order>
<item id='1' quantity='2'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<order>;
trace(myXML.item[0].menuName.toXMLString());
// <menuName>burger</menuName>
trace(myXML.item[0].menuName.toString());
// burger
If you use the
trace()
method without specifying
toString()
or
toXMLString()
,
the data is converted using the
toString()
method
by default, as this code shows:
var myXML:XML =
<order>
<item id='1' quantity='2'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<order>;
trace(myXML.item[0].menuName);
// burger
When using the
trace()
method to debug code,
you will often want to use the
toXMLString()
method
so that the
trace()
method outputs more complete
data.