Note: Use the
The clone of the node that is returned is no longer associated with the tree of the cloned item.
Consequently,
If no namespace is defined for the specified prefix, the method returns
If you specify an empty string (
If there is no
For top-level XMLDocument objects (those created with the constructor),
the
The
In Flash Player, the built-in XMLNode class only supports
var myColor:String = doc.firstChild.attributes.color
This property is undefined for text nodes (
You can access the namespace prefix through the
If the XML node does not have a prefix, the value of the
You can use the
The
The XMLDocument class, as well as XMLNode and XMLNodeType, are present for backward compatibility. The functionality for loading XML documents can now be found in the URLLoader class.
The following example creates an XML object by parsing the XML text specified in the source
parameter, and populates the newly created XML object with the resulting XML document tree:
Note: Use the
createElement()
method:
createTextNode()
method, and places them into existing XML nodes:
XML.docTypeDecl
property to set the DOCTYPE
declaration for an XML object:
my_xml
.docTypeDecl = "<!DOCTYPE greeting SYSTEM \"hello.dtd\">";
The legacy ActionScript XML parser is not a validating parser. The
If no
Then create a SWF file in the same directory as the XML file. Include the following script in the SWF:
When you test the SWF file, the following output is generated:
Consider the following XMLDocument object:
In this example, the
You must use the
If there is more than one XMLNode with the same
foyer
tag comprises fourteen space characters. To run this example, create a text file named flooring.xml, and copy the following tags into it:
Create a new Flash document named flooring.fla and save it to the same directory as the XML file. Place the following code into the main Timeline:
If you then change the setting of flooring.ignoreWhite
to false
, or simply remove that line of code entirely, the fourteen space characters in the foyer
tag will be preserved:
The XML_blogTracker.fla and XML_languagePicker.fla files in the ActionScript samples folder also contain a code example. The following are typical paths to this folder:
You can set the
my_txt
that has the same dimensions as the Stage. The text field displays properties of the XML packet that loads into the SWF file. The doc type declaration displays in my_txt
. Add the following ActionScript to your FLA or AS file:
var my_fmt:TextFormat = new TextFormat();
my_fmt.font = "_typewriter";
my_fmt.size = 12;
my_fmt.leftMargin = 10;
this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, Stage.width, Stage.height);
my_txt.border = true;
my_txt.multiline = true;
my_txt.wordWrap = true;
my_txt.setNewTextFormat(my_fmt);
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean) {
var endTime:Number = getTimer();
var elapsedTime:Number = endTime-startTime;
if (success) {
my_txt.text = "xmlDecl:"+newline+my_xml.xmlDecl+newline+newline;
my_txt.text += "contentType:"+newline+my_xml.contentType+newline+newline;
my_txt.text += "docTypeDecl:"+newline+my_xml.docTypeDecl+newline+newline;
my_txt.text += "packet:"+newline+my_xml.toString()+newline+newline;
} else {
my_txt.text = "Unable to load remote XML."+newline+newline;
}
my_txt.text += "loaded in: "+elapsedTime+" ms.";
};
my_xml.load("http://www.helpexamples.com/crossdomain.xml");
var startTime:Number = getTimer();