注意:XML ドキュメントツリーにエレメントとテキストノードを追加するには、
返されるノードのクローンは、クローン作成元のアイテムのツリーとは関連がなくなります。その結果、
指定された接頭辞に対して定義されている名前空間がない場合は、
空のストリング(
その URI に対応する
トップレベルの XMLDocument オブジェクト(コンストラクターで作成されたオブジェクト)の場合は、
Flash Player に組み込まれている XMLNode クラスがサポートするのは、
var myColor:String = doc.firstChild.attributes.color
テキストノード(
名前空間の接頭辞には、XML ノードオブジェクトの
XML ノードに接頭辞が付いていない場合、
XML ノードオブジェクトの
XMLDocument クラスと、XMLNode および XMLNodeType があるのは、後方互換性を維持するためです。XML ドキュメントをロードする機能は、現在では URLLoader クラスにあります。
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:
注意:XML ドキュメントツリーにエレメントとテキストノードを追加するには、
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\">";
古い ActionScript の XML パーサーは、妥当性検証用パーサーではありません。
解析中に
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:
例えば、次のような XMLDocument オブジェクトを検討します。
この例では、この XMLDocument オブジェクトの
XMLDocument オブジェクトの
同じ
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:
次のコードに示すように、XMLDocument オブジェクトごとに
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();