If you use the
trace()
is converted using the
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 so that the
toXMLString()
Converting strings to XML objects
You can use the
new XML()
var x:XML = new XML("<a>test</a>");
If you attempt to convert a string to XML from a string that represents invalid XML or XML
that is not well formed, a run-time error is thrown, as follows:
var x:XML = new XML("<a>test"); // throws an error
Converting attribute values, names, and text values
from strings
All XML attribute values, names, and text values are String data types, and you may need to
convert these to other data types. For example, the following code uses the
to convert text values to numbers:
var myXML:XML =
<order>
<item>
</item>
<item>
</item>
</order>;
var total:XML = <total>0</total>;
myXML.appendChild(total);
for each (var item:XML in myXML.item)
method without specifying
method by default, as this code shows:
toString()
method to debug code, you will often want to use the
trace()
constructor to create an XML object from a string, as follows:
<price>3.95</price>
<price>1.00</price>
or
toString()
method outputs more complete data.
, the data
toXMLString()
function
Number()
XML type conversion
329