パッケージトップレベル
public final dynamic class XML
継承XML Inheritance Object

XML クラスには、XML オブジェクトを操作するためのメソッドとプロパティが含まれています。XMLList、Namespace、および QName などのクラスと同様、XML クラスには ECMAScript for XML (E4X) 仕様 (ECMA-357 Edition 2) で定義されている強力な XML 処理規格が実装されています。

toXMLString() メソッドは、XML オブジェクトに単純内容が含まれるか、複合内容が含まれるかに関係なく、XML オブジェクトのストリング表現を返します。

メモ : ActionScript 2.0 の XML クラスと関連クラスは XMLDocument というクラス名に変更され、flash.xml パッケージに移行されています。XMLDocument は、後方互換性を維持する目的で ActionScript 3.0 に残されているものです。

例の表示

関連項目

Namespace
QName
XMLList
XML.toXMLString()
ECMAScript for XML (E4X) specification (ECMA-357 edition 2)
XML オブジェクト


パブリックプロパティ
 プロパティ定義
 Inheritedconstructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクタ関数への参照です。
Object
  ignoreComments : Boolean
[static] XML オブジェクトがソースの XML データを解析する際に、XML コメントを無視するかどうかを決定します。
XML
  ignoreProcessingInstructions : Boolean
[static] XML オブジェクトがソースの XML データを解析する際に、XML 処理命令を無視するかどうかを決定します。
XML
  ignoreWhitespace : Boolean
[static] テキストノードの先頭および最後の空白文字を、解析時に無視するかどうかを決定します。
XML
  prettyIndent : int
[static] XML.prettyPrinting プロパティを true に設定した場合に、toString() メソッドと toXMLString() メソッドが適用するインデントの量を決定します。
XML
  prettyPrinting : Boolean
[static] toString() メソッドと toXMLString() メソッドが、タグ間の空白文字を正規化するかどうかを決定します。
XML
 Inheritedprototype : Object
[static] クラスまたは関数オブジェクトのプロトタイプオブジェクトへの参照です。
Object
パブリック Methods
 メソッド定義
  
XML(value:Object)
新しい XML オブジェクトを作成します。
XML
  
XML オブジェクトのスコープ内の名前空間セットに名前空間を追加します。
XML
  
指定された子を XML オブジェクトのプロパティの最後に追加します。
XML
  
attribute(attributeName:*):XMLList
attributeName パラメータに一致する名前を持つ属性の XML 値を返します。
XML
  
指定された XML オブジェクトの属性値のリストを返します。
XML
  
child(propertyName:Object):XMLList
XML オブジェクトの子を列挙します。
XML
  
親のコンテキスト内でのこの XML オブジェクトの 0 から始まるインデックス位置を識別します。
XML
  
XML オブジェクトの子を、出現する順序で列挙します。
XML
  
XML コメントを持つ XML オブジェクトのプロパティを列挙します。
XML
  
XML オブジェクトと、指定された value パラメータを比較します。
XML
  
copy():XML
指定された XML オブジェクトのコピーを返します。
XML
  
[static] プロパティ ignoreCommentsignoreProcessingInstructionsignoreWhitespaceprettyIndent、および prettyPrinting をデフォルト値に設定したオブジェクトを返します。
XML
  
指定された name パラメータを持つ XML オブジェクトのすべての子孫 (子、孫、ひ孫など) を返します。
XML
  
elements(name:Object = *):XMLList
XML オブジェクトのエレメントを列挙します。
XML
  
XML オブジェクトに複合内容が含まれるかどうかを確認します。
XML
  
オブジェクトに p パラメータで指定されたプロパティがあるかどうかを確認します。
XML
  
XML オブジェクトに単純内容が含まれるかどうかを確認します。
XML
  
オブジェクトの親に基づいて、XML オブジェクトの名前空間を列挙します。
XML
  
insertChildAfter(child1:Object, child2:Object):*
指定された child2 パラメータを、この XML オブジェクトの child1 パラメータの後に挿入し、その結果のオブジェクトを返します。
XML
  
insertChildBefore(child1:Object, child2:Object):*
指定された child2 パラメータを、この XML オブジェクトの child1 パラメータの前に挿入し、その結果のオブジェクトを返します。
XML
 Inherited
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
Object
  
XML オブジェクトの場合、このメソッドは常に整数 1 を返します。
XML
  
XML オブジェクトの修飾名のローカル名部分を指定します。
XML
  
XML オブジェクトの修飾名を指定します。
XML
  
namespace(prefix:String = null):*
パラメータを指定しない場合、この XML オブジェクトの修飾名に関連付けられている名前空間を指定します。
XML
  
親のコンテキストで XML オブジェクトに関連付けられている名前空間宣言を列挙します。
XML
  
ノードのタイプ (テキスト、コメント、処理命令、属性、またはエレメント) を指定します。
XML
  
XML オブジェクトとすべての子孫の XML オブジェクトについて、隣接するテキストノードを結合し、空のテキストノードを削除します。
XML
  
parent():*
XML オブジェクの親を返します。
XML
  
指定された child オブジェクトのコピーを、このエレメント内の既存のすべての XML プロパティの前に挿入します。
XML
  
name パラメータを指定した場合、その name を持つ処理命令を含む XML オブジェクトのすべての子を列挙します。
XML
  
XML オブジェクトに適用される for..in ステートメント内で反復処理されるプロパティセット内に、プロパティ p があるかどうかを確認します。
XML
  
このオブジェクトとすべての子孫に指定された名前空間を削除します。
XML
  
replace(propertyName:Object, value:XML):XML
propertyName パラメータで指定されたプロパティを、指定された value パラメータに置き換えます。
XML
  
XML オブジェクトの子プロパティを、value パラメータで指定された XML プロパティのセットに置き換えます。
XML
  
XML オブジェクトのローカル名を、指定された name パラメータに変更します。
XML
  
XML オブジェクトの名前を、指定された修飾名または属性名に設定します。
XML
  
XML オブジェクトに関連付けられている名前空間を設定します。
XML
 Inherited
ループ処理に対するダイナミックプロパティの可用性を設定します。
Object
  
[static] XML プロパティ ignoreCommentsignoreProcessingInstructionsignoreWhitespaceprettyIndent、および prettyPrinting の値を設定します。
XML
  
[static] プロパティ ignoreCommentsignoreProcessingInstructionsignoreWhitespaceprettyIndent、および prettyPrinting を取得します。
XML
  
XML テキストノードを表す XML オブジェクトのすべての XML プロパティの XMLList オブジェクトを返します。
XML
  
XML オブジェクトのストリング表現を返します。
XML
  
XML オブジェクトのストリング表現を返します。
XML
  
XML オブジェクトを返します。
XML
プロパティの詳細
ignoreCommentsプロパティ
ignoreComments:Boolean  [read-write]

XML オブジェクトがソースの XML データを解析する際に、XML コメントを無視するかどうかを決定します。デフォルトでは、コメントを無視します (true)。XML コメントを含めるには、このプロパティを false に設定します。ignoreComments プロパティは、myXMLObject.child(*).toXMLString() などのメソッドの呼び出し時でなく、XML の解析時にのみ使用します。ソースの XML にコメントノードが含まれる場合、このノードは XML の解析時には保持されるか、または破棄されます。

実装
    public static function get ignoreComments():Boolean
    public function set ignoreComments(value:Boolean):void

関連項目



This example shows the effect of setting XML.ignoreComments to false and to true:
 XML.ignoreComments = false; var xml1:XML = <foo> <!-- comment --> </foo>; trace(xml1.toXMLString()); // <foo><!-- comment --></foo>

XML.ignoreComments = true; var xml2:XML = <foo> <!-- example --> </foo>; trace(xml2.toXMLString()); // <foo/>

ignoreProcessingInstructionsプロパティ 
ignoreProcessingInstructions:Boolean  [read-write]

XML オブジェクトがソースの XML データを解析する際に、XML 処理命令を無視するかどうかを決定します。デフォルトでは、処理命令を無視します (true)。XML 処理命令を含めるには、このプロパティを false に設定します。ignoreProcessingInstructions プロパティは、myXMLObject.child(*).toXMLString() などのメソッドの呼び出し時でなく、XML の解析時にのみ使用します。ソースの XML に処理命令ノードが含まれる場合、このノードは XML の解析時には保持されるか、または破棄されます。

実装
    public static function get ignoreProcessingInstructions():Boolean
    public function set ignoreProcessingInstructions(value:Boolean):void

関連項目



This example shows the effect of setting XML.ignoreProcessingInstructions to false and to true:
 XML.ignoreProcessingInstructions = false; var xml1:XML = <foo> <?exampleInstruction ?> </foo>; trace(xml1.toXMLString()); // <foo><?exampleInstruction ?></foo>

XML.ignoreProcessingInstructions = true; var xml2:XML = <foo> <?exampleInstruction ?> </foo>; trace(xml2.toXMLString()); // <foo/>

ignoreWhitespaceプロパティ 
ignoreWhitespace:Boolean  [read-write]

テキストノードの先頭および最後の空白文字を、解析時に無視するかどうかを決定します。デフォルトでは、空白文字を無視します (true)。テキストノードが 100% 空白文字で、ignoreWhitespace プロパティが true に設定されている場合、ノードは作成されません。テキストノード内の空白文字を表示するには、ignoreWhitespace プロパティを false に設定します。

実装
    public static function get ignoreWhitespace():Boolean
    public function set ignoreWhitespace(value:Boolean):void


This example shows the effect of setting XML.ignoreWhitespace to false and to true:
 XML.ignoreWhitespace = false; var xml1:XML = <foo>    </foo>; trace(xml1.children().length()); // 1

XML.ignoreWhitespace = true; var xml2:XML = <foo>    </foo>; trace(xml2.children().length()); // 0

prettyIndentプロパティ 
prettyIndent:int  [read-write]

XML.prettyPrinting プロパティを true に設定した場合に、toString() メソッドと toXMLString() メソッドが適用するインデントの量を決定します。インデントは、タブ文字でなく、空白文字で適用されます。 デフォルト値は 2 です。

実装
    public static function get prettyIndent():int
    public function set prettyIndent(value:int):void

関連項目



This example shows the effect of setting the XML.prettyIndent static property:
 var xml:XML = <foo><bar/></foo>; XML.prettyIndent = 0; trace(xml.toXMLString());

XML.prettyIndent = 1; trace(xml.toXMLString());

XML.prettyIndent = 2; trace(xml.toXMLString());

prettyPrintingプロパティ 
prettyPrinting:Boolean  [read-write]

toString() メソッドと toXMLString() メソッドが、タグ間の空白文字を正規化するかどうかを決定します。デフォルト値は true です。

実装
    public static function get prettyPrinting():Boolean
    public function set prettyPrinting(value:Boolean):void

関連項目



This example shows the effect of setting XML.prettyPrinting static property:
 var xml:XML = <foo><bar/></foo>; XML.prettyPrinting = false; trace(xml.toXMLString());

XML.prettyPrinting = true; trace(xml.toXMLString());

コンストラクタの詳細
XML()コンストラクタ
public 関数 XML(value:Object)

新しい XML オブジェクトを作成します。XML クラスのメソッドを呼び出す前に、コンストラクタを使用して XML オブジェクトを作成する必要があります。

toXMLString() メソッドは、XML オブジェクトに単純内容が含まれるか、複合内容が含まれるかに関係なく、XML オブジェクトのストリング表現を返します。

パラメータ
value:Object — トップレベル関数 XML() によって XML に変換可能なオブジェクトです。

関連項目

メソッドの詳細
addNamespace()メソッド
AS3 function addNamespace(ns:Object):XML

XML オブジェクトのスコープ内の名前空間セットに名前空間を追加します。その名前空間が XML オブジェクトのスコープ内の名前空間セットに既に存在する (指定されたパラメータに一致する接頭辞を持つ) 場合、既存の名前空間の接頭辞は undefined に設定されます。入力パラメータが Namespace オブジェクトの場合は、このオブジェクトが直接使用されます。入力パラメータが QName オブジェクトの場合は、新しい名前空間の作成に入力パラメータの URI が使用され、それ以外の場合は、入力パラメータは String に変換され、名前空間がその String から作成されます。

パラメータ
ns:Object — XML オブジェクトに追加する名前空間です。

戻り値
XML — 名前空間が追加された新しい XML オブジェクトです。

関連項目



This example uses a namespace defined in one XML object and applies it to another XML object:
 var xml1:XML = <ns:foo xmlns:ns="www.example.com/ns" />; var nsNamespace:Namespace = xml1.namespace();

var xml2:XML = <bar />; xml2.addNamespace(nsNamespace); trace(xml2.toXMLString()); // <bar xmlns:ns="www.example.com/ns"/>

appendChild()メソッド 
AS3 function appendChild(child:Object):XML

指定された子を XML オブジェクトのプロパティの最後に追加します。appendChild() メソッドは、XML オブジェクト、XMLList オブジェクト、または他の任意のデータ型 (後で String データ型に変換されます) を受け取ります。

XML ノードを削除するには、delete (XML) 演算子を使用します。

パラメータ
child:Object — 追加する XML オブジェクトです。

戻り値
XML — 結果として作成される XML オブジェクトです。

関連項目



This example appends a new element to the end of the child list of an XML object:
 var xml:XML = <body> <p>hello</p> </body>;
        
xml.appendChild(<p>world</p>); trace(xml.p[0].toXMLString()); // <p>hello</p> trace(xml.p[1].toXMLString()); // <p>world</p>

attribute()メソッド 
AS3 function attribute(attributeName:*):XMLList

attributeName パラメータに一致する名前を持つ属性の XML 値を返します。属性は XML エレメント内にあります。次の例では、エレメントは値 "boy" が割り当てられた "gender" という名前の属性を持ちます。<first gender="boy">John</first>

attributeName パラメータには任意のデータ型を指定できますが、String データ型を使用するのが最も一般的です。QName オブジェクト以外のオブジェクトを渡した場合、attributeName パラメータは toString() メソッドを使用してパラメータをストリングに変換します。

修飾名参照が必要な場合は、QName オブジェクトで渡すことができます。QName オブジェクトは名前空間とローカル名を定義するもので、属性の修飾名の定義に使用することができます。したがって、attribute(qname) の呼び出しは attribute(qname.toString()) の呼び出しと同じではありません。

パラメータ
attributeName:* — 属性の名前。

戻り値
XMLList — XMLList オブジェクトまたは空の XMLList オブジェクトです。属性値が定義されていない場合は空の XMLList を返します。

関連項目



This example shows a QName object passed into the attribute() method. The localName property is attr and the namespace property is ns.
 var xml:XML = <ns:node xmlns:ns = "http://uri" ns:attr = '7' /> var qn:QName = new QName("http://uri", "attr"); trace (xml.attribute(qn)); // 7

To return an attribute with a name that matches an ActionScript reserved word, use the attribute() method instead of the attribute identifier (@) operator, as in the following example:
 var xml:XML = <example class="first" /> trace(xml.attribute("class"));

attributes()メソッド 
AS3 function attributes():XMLList

指定された XML オブジェクトの属性値のリストを返します。attributes() メソッドと共に name() メソッドを使用して属性の名前を返します。すべての属性の名前を返すには、@* を使用します。

戻り値
XMLList — 属性値のリストです。.

関連項目



The following example returns the name of the attribute:
 var xml:XML=<example id='123' color='blue'/> trace(xml.attributes()[1].name()); //color

This example returns the names of all the attributes:
 
var xml:XML = <example id='123' color='blue'/> var attNamesList:XMLList = xml.@*;

trace (attNamesList is XMLList); // true trace (attNamesList.length()); // 2

for (var i:int = 0; i < attNamesList.length(); i++) { trace (typeof (attNamesList[i])); // xml trace (attNamesList[i].nodeKind()); // attribute trace (attNamesList[i].name()); // id and color }

child()メソッド 
AS3 function child(propertyName:Object):XMLList

XML オブジェクトの子を列挙します。XML の 1 つの子は、1 つの XML エレメント、テキストノード、コメント、または処理命令です。

propertyName パラメータを使用して、特定の XML の子の内容を列挙します。たとえば、<first> という名前の子の内容を返すには、child.name("first") を使用します。子のインデックス番号を使用しても同じ結果が得られます。インデックス番号は、複数の XML の子のリスト内での子の位置を識別します。たとえば、name.child(0) はリスト内の先頭の子を返します。

XML ドキュメント内のすべての子を出力するにはアスタリスク (*) を使用します。たとえば、doc.child("*") となります。

子の総数を出力するには、アスタリスク (*) パラメータを指定した child() メソッドと共に length() を使用します。たとえば、numChildren = doc.child("*").length() となります。

パラメータ
propertyName:Object — XML の子のエレメント名または整数です。

戻り値
XMLList — 入力パラメータに一致する子ノードの XMLList オブジェクトです。

関連項目



This example shows the use of the child() method to identify child elements with a specified name:
 var xml:XML = <foo> <bar>text1</bar> <bar>text2</bar> </foo>; trace(xml.child("bar").length());  // 2 trace(xml.child("bar")[0].toXMLString()); // <bar>text1</bar> trace(xml.child("bar")[1].toXMLString()); // <bar>text2</bar>

childIndex()メソッド 
AS3 function childIndex():int

親のコンテキスト内でのこの XML オブジェクトの 0 から始まるインデックス位置を識別します。

戻り値
int — オブジェクトの位置です。正の整数だけでなく、-1 も返します。

関連項目



This example shows the use of the childIndex() method:
 var xml:XML = <foo> <bar /> text <bob /> </foo>; trace(xml.bar.childIndex()); // 0 trace(xml.bob.childIndex()); // 2

children()メソッド 
AS3 function children():XMLList

XML オブジェクトの子を、出現する順序で列挙します。XML の 1 つの子は、1 つの XML エレメント、テキストノード、コメント、または処理命令です。

戻り値
XMLList — XML オブジェクトの子の XMLList オブジェクトです。

関連項目



This example shows the use of the children() method:
 XML.ignoreComments = false; XML.ignoreProcessingInstructions = false; var xml:XML = <foo id="22"> <bar>44</bar> text <!-- comment --> <?instruction ?> </foo>; trace(xml.children().length()); // 4 trace(xml.children()[0].toXMLString()); // <bar>44</bar> trace(xml.children()[1].toXMLString()); // text trace(xml.children()[2].toXMLString()); // <!-- comment --> trace(xml.children()[3].toXMLString()); // <?instruction ?>

comments()メソッド 
AS3 function comments():XMLList

XML コメントを持つ XML オブジェクトのプロパティを列挙します。

戻り値
XMLList — コメントを持つプロパティの XMLList オブジェクトです。

関連項目



This example shows the use of the comments() method:
 XML.ignoreComments = false; var xml:XML = <foo> <!-- example --> <!-- example2 --> </foo>; trace(xml.comments().length()); // 2 trace(xml.comments()[1].toXMLString()); // <!-- example2 -->

contains()メソッド 
AS3 function contains(value:XML):Boolean

XML オブジェクトと、指定された value パラメータを比較します。

パラメータ
value:XML — 現在の XML オブジェクトと比較する値です。

戻り値
Boolean — XML オブジェクトが value パラメータに一致する場合は true、それ以外の場合は false を返します。

関連項目



This example shows the use of the contains() method:
 var xml:XML = <order> <item>Rice</item> <item>Kung Pao Shrimp</item> </order>; trace(xml.item[0].contains(<item>Rice</item>)); // true trace(xml.item[1].contains(<item>Kung Pao Shrimp</item>)); // true trace(xml.item[1].contains(<item>MSG</item>)); // false

copy()メソッド 
AS3 function copy():XML

指定された XML オブジェクトのコピーを返します。コピーとはノードのツリー全体の複製です。コピーされた XML オブジェクトには親はなく、parent() メソッドを呼び出そうとすると null が返されます。

戻り値
XML — オブジェクトのコピーです。

関連項目



This example shows that the copy() method creates a new instance of an XML object. When you modify the copy, the original remains unchanged:
 var xml1:XML = <foo />; var xml2:XML = xml1.copy(); xml2.appendChild(<bar />); trace(xml1.bar.length()); // 0 trace(xml2.bar.length()); // 1

defaultSettings()メソッド 
AS3 static function defaultSettings():Object

プロパティ ignoreCommentsignoreProcessingInstructionsignoreWhitespaceprettyIndent、および prettyPrinting をデフォルト値に設定したオブジェクトを返します。デフォルト値は次のとおりです。

メモ : このメソッドは XML クラスのインスタンスには適用しません。コード var df:Object = XML.defaultSettings() のように、XML に適用します。

戻り値
Object — プロパティをデフォルト値に設定したオブジェクトです。

関連項目



The following example shows: how to apply some custom settings (for including comments and processing instructions) prior to setting an XML object; how to then revert back to the default settings before setting another XML object; and then how to set the custom settings again (for setting any more XML objects):
 XML.ignoreComments = false; XML.ignoreProcessingInstructions = false; var customSettings:Object = XML.settings();

var xml1:XML = <foo> <!-- comment --> <?instruction ?> </foo>; trace(xml1.toXMLString()); //    <foo> //        <!-- comment --> //         <?instruction ?> //    </foo>

XML.setSettings(XML.defaultSettings()); var xml2:XML = <foo> <!-- comment --> <?instruction ?> </foo>; trace(xml2.toXMLString());

descendants()メソッド 
AS3 function descendants(name:Object = *):XMLList

指定された name パラメータを持つ XML オブジェクトのすべての子孫 (子、孫、ひ孫など) を返します。name パラメータはオプションです。name パラメータには、QName オブジェクト、String データ型、または他の任意のデータ型 (後で String データ型に変換されます) を指定できます。

すべての子孫を返すには、"*" パラメータを使用します。パラメータを指定しない場合はストリング "*" が渡され、XML オブジェクトのすべての子孫が返されます。

パラメータ
name:Object (default = *) — 照合するエレメントの名前です。

戻り値
XMLList — 一致する子孫の XMLList オブジェクトです。子孫がない場合は、空の XMLList オブジェクトを返します。

関連項目



To return descendants with names that match ActionScript reserved words, use the descendants() method instead of the descendant (..) operator, as in the following example:
 var xml:XML = <enrollees> <student id="239"> <class name="Algebra" /> <class name="Spanish 2"/> </student> <student id="206"> <class name="Trigonometry" /> <class name="Spanish 2" /> </student> </enrollees> trace(xml.descendants("class"));

The following example shows that the descendants() method returns an XMLList object that contains all descendant objects, including children, grandchildren, and so on:
 XML.ignoreComments = false; var xml:XML = <body> <!-- comment --> text1 <a> <b>text2</b> </a> </body>; trace(xml.descendants("*").length()); // 5 trace(xml.descendants("*")[0]); // // <!-- comment --> trace(xml.descendants("*")[1].toXMLString()); // text1 trace(xml.descendants("a").toXMLString()); // <a><b>text2</b></a> trace(xml.descendants("b").toXMLString()); // <b>text2</b>

elements()メソッド 
AS3 function elements(name:Object = *):XMLList

XML オブジェクトのエレメントを列挙します。エレメントは、<first></first> のように開始タグと終了タグで構成されます。name パラメータはオプションです。name パラメータには、QName オブジェクト、String データ型、または他の任意のデータ型 (後で String データ型に変換されます) を指定できます。name パラメータは、特定のエレメントの列挙に使用します。たとえば、<first>John</first> では、エレメント "first" は "John" を返します。

すべてのエレメントを列挙するには、パラメータにアスタリスク (*) を使用します。アスタリスクはデフォルトパラメータでもあります。

エレメントの総数を出力するには、アスタリスクパラメータと共に length() メソッドを使用します。たとえば、numElement = addressbook.elements("*").length() となります。

パラメータ
name:Object (default = *) — エレメントの名前です。エレメントの名前は山括弧で囲まれています。たとえば、<first></first>name は "first" です。

戻り値
XMLList — エレメントの内容の XMLList オブジェクトです。エレメントの内容は開始タグと終了タグで囲まれます。すべてのエレメントの呼び出しでアスタリスク (*) を使用すると、エレメントのタグと内容の両方を返します。

関連項目



The following example shows that the elements() method returns a list of elements only — not comments, text properties, or processing instructions:
 var xml:XML = <foo> <!-- comment --> <?instruction ?> text <a>1</a> <b>2</b> </foo>; trace(xml.elements("*").length()); // 2 trace(xml.elements("*")[0].toXMLString()); // <a>1</a> trace(xml.elements("b").length()); // 1 trace(xml.elements("b")[0].toXMLString()); // <b>2</b>

To return elements with names that match ActionScript reserved words, use the elements() method instead of the XML dot (.) operator, as in the following example:
 var xml:XML = <student id="206"> <class name="Trigonometry" /> <class name="Spanish 2" /> </student> trace(xml.elements("class"));

hasComplexContent()メソッド 
AS3 function hasComplexContent():Boolean

XML オブジェクトに複合内容が含まれるかどうかを確認します。子エレメントを持つ場合、XML オブジェクトには複合内容が含まれます。属性、コメント、処理命令、およびテキストノードを表す XML オブジェクトは複合内容を持ちません。ただし、これらを含むオブジェクトでも、子エレメントを持つ場合は、複合内容を含んでいると見なされます。

戻り値
Boolean — XML オブジェクトに複合内容が含まれる場合は true、それ以外の場合は false を返します。

関連項目



The following example shows an XML object with one property named a that has simple content and one property named a that has complex content:
 var xml:XML = <foo> <a> text </a> <a> <b/> </a> </foo>; trace(xml.a[0].hasComplexContent()); // false trace(xml.a[1].hasComplexContent()); // true

trace(xml.a[0].hasSimpleContent()); // true trace(xml.a[1].hasSimpleContent()); // false

hasOwnProperty()メソッド 
AS3 function hasOwnProperty(p:String):Boolean

オブジェクトに p パラメータで指定されたプロパティがあるかどうかを確認します。

パラメータ
p:String — 照合するプロパティです。

戻り値
Boolean — パラメータが存在する場合は true、それ以外は false を返します。

関連項目



The following example uses the hasOwnProperty() method to ensure that a property (b) exists prior to evaluating an expression (b == "11") that uses the property:
 var xml:XML = <foo> <a /> <a> <b>10</b> </a> <a> <b>11</b> </a> </foo>; trace(xml.a.(hasOwnProperty("b") && b == "11")); 
If the last line in this example were the following, Flash Player would throw an exception since the first element named a does not have a property named b:

trace(xml.a.(b == "11"));



The following example uses the hasOwnProperty() method to ensure that a property (item) exists prior to evaluating an expression (item.contains("toothbrush")) that uses the property:
 var xml:XML = <orders> <order id='1'> <item>toothbrush</item> <item>toothpaste</item> </order> <order> <returnItem>shoe polish</returnItem> </order> </orders>; trace(xml.order.(hasOwnProperty("item") && item.contains("toothbrush")));

hasSimpleContent()メソッド 
AS3 function hasSimpleContent():Boolean

XML オブジェクトに単純内容が含まれるかどうかを確認します。XML オブジェクトが子エレメントを持たないテキストノード、属性ノード、または XML エレメントを表す場合には、このオブジェクトには単純内容が含まれます。コメントおよび処理命令を表す XML オブジェクトには単純内容は含まれません

戻り値
Boolean — XML オブジェクトに単純内容が含まれる場合は true、それ以外の場合は false を返します。

関連項目



The following example shows an XML object with one property named a that has simple content and one property named a that has complex content:
 var xml:XML = <foo> <a> text </a> <a> <b/> </a> </foo>; trace(xml.a[0].hasComplexContent()); // false trace(xml.a[1].hasComplexContent()); // true

trace(xml.a[0].hasSimpleContent()); // true trace(xml.a[1].hasSimpleContent()); // false

inScopeNamespaces()メソッド 
AS3 function inScopeNamespaces():Array

オブジェクトの親に基づいて、XML オブジェクトの名前空間を列挙します。

戻り値
Array — Namespace オブジェクトの配列です。

関連項目

insertChildAfter()メソッド 
AS3 function insertChildAfter(child1:Object, child2:Object):*

指定された child2 パラメータを、この XML オブジェクトの child1 パラメータの後に挿入し、その結果のオブジェクトを返します。child1 パラメータが null の場合、このメソッドは XML オブジェクトのすべての子の、つまり先頭child2 の内容を挿入します。child1 を指定し、これが XML オブジェクトに存在しない場合、XML オブジェクトを変更しないで、undefined を返します。

テキスト、属性、コメント、パイなどのエレメントでない XML の子に対してこのメソッドを呼び出すと、undefined を返します。

XML ノードを削除するには、delete (XML) 演算子を使用します。

パラメータ
child1:Objectchild2 の前に挿入するソースオブジェクト内のオブジェクトです。
 
child2:Object — 挿入するオブジェクトです。

戻り値
* — 結果として作成される XML オブジェクトまたは undefined です。

関連項目



The following example appends an element to the end of the child elements of an XML object:
 var xml:XML = <menu> <item>burger</item> <item>soda</item> </menu>; xml.insertChildAfter(xml.item[0], <saleItem>fries</saleItem>); trace(xml); 
The trace() output is the following:
 <menu>      <item>burger</item>      <saleItem>fries</saleItem>      <item>soda</item>  </menu>


insertChildBefore()メソッド 
AS3 function insertChildBefore(child1:Object, child2:Object):*

指定された child2 パラメータを、この XML オブジェクトの child1 パラメータの前に挿入し、その結果のオブジェクトを返します。child1 パラメータが null の場合、このメソッドは XML オブジェクトのすべての子の、つまり最後child2 の内容を挿入します。child1 を指定し、これが XML オブジェクトに存在しない場合、XML オブジェクトを変更しないで、undefined を返します。

テキスト、属性、コメント、パイなどのエレメントでない XML の子に対してこのメソッドを呼び出すと、undefined を返します。

XML ノードを削除するには、delete (XML) 演算子を使用します。

パラメータ
child1:Objectchild2 の後に挿入するソースオブジェクト内のオブジェクトです。
 
child2:Object — 挿入するオブジェクトです。

戻り値
* — 結果として作成される XML オブジェクトまたは undefined です。

関連項目



The following example appends an element to the end of the child elements of an XML object:
 var xml:XML = <menu> <item>burger</item> <item>soda</item> </menu>; xml.insertChildBefore(xml.bar[0], <saleItem>fries</saleItem>); trace(xml); 
The trace() output is the following:
<menu>      <saleItem>fries</saleItem>      <item>burger</item>      <item>soda</item>  </menu>


length()メソッド 
AS3 function length():int

XML オブジェクトの場合、このメソッドは常に整数 1 を返します。XMLList クラスの length() メソッドは、1 つの値のみを含む XMLList オブジェクトの値 1 を返します。

戻り値
int — どのような XML オブジェクトに対しても、常に 1 を返します。

関連項目

localName()メソッド 
AS3 function localName():Object

XML オブジェクトの修飾名のローカル名部分を指定します。

戻り値
Object — String または null のいずれかのローカル名です。

関連項目



The following example illustrates the use of the localName() method:
 var xml:XML = <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

                        <soap:Body xmlns:wx = "http://example.com/weather"> <wx:forecast> <wx:city>Quito</wx:city> </wx:forecast> </soap:Body> </soap:Envelope>;
        
trace(xml.localName()); // Envelope

name()メソッド 
AS3 function name():Object

XML オブジェクトの修飾名を指定します。

戻り値
Object — 修飾名には、QName または null のいずれかを指定します。

関連項目



The following example illustrates the use of the name() method to get the qualified name of an XML object:
 var xml:XML = <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

                        <soap:Body xmlns:wx = "http://example.com/weather"> <wx:forecast> <wx:city>Quito</wx:city> </wx:forecast> </soap:Body> </soap:Envelope>;
        
trace(xml.name().localName); // Envelope trace(xml.name().uri); // "http://www.w3.org/2001/12/soap-envelope"

The following example illustrates the use of the name() method called on an XML property, on a text element, and on an attribute:
 var xml:XML = <foo x="15" y="22"> text </foo>;
        
trace(xml.name().localName); // foo trace(xml.name().uri == ""); // true trace(xml.children()[0]); // text trace(xml.children()[0].name()); // null trace(xml.attributes()[0]); // 15 trace(xml.attributes()[0].name()); // x

namespace()メソッド 
AS3 function namespace(prefix:String = null):*

パラメータを指定しない場合、この XML オブジェクトの修飾名に関連付けられている名前空間を指定します。prefix パラメータで指定した場合、prefix パラメータに一致し、XML オブジェクトのスコープ内にある名前空間を返します。このような条件に一致する名前空間がなかった場合、メソッドは undefined を返します。

パラメータ
prefix:String (default = null) — 照合する接頭辞です。

戻り値
*nullundefined、または名前空間を返します。

関連項目



The following example uses the namespace() method to get the namespace of an XML object and assign it to a Namespace object named soap which is then used in identifying a property of the xml object (xml.soap::Body[0]):
 var xml:XML = <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

                        <soap:Body xmlns:wx = "http://example.com/weather"> <wx:forecast> <wx:city>Quito</wx:city> </wx:forecast> </soap:Body> </soap:Envelope>;
        
var soap:Namespace = xml.namespace(); trace(soap.prefix); // soap trace(soap.uri); // http://www.w3.org/2001/12/soap-envelope

var body:XML = xml.soap::Body[0]; trace(body.namespace().prefix); // soap trace(xml.namespace().uri); // http://www.w3.org/2001/12/soap-envelope trace(body.namespace("wx").uri); // "http://example.com/weather"

The following example uses the namespace() method to get the default namespace for a node, as well as the namespace for a specific prefix ("dc"):
 var xml:XML = <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/"> <!-- ... --> </rdf:RDF>;
                    
trace(xml.namespace()); // http://www.w3.org/1999/02/22-rdf-syntax-ns# trace(xml.namespace("dc")); // http://purl.org/dc/elements/1.1/ trace(xml.namespace("foo")); // undefined

namespaceDeclarations()メソッド 
AS3 function namespaceDeclarations():Array

親のコンテキストで XML オブジェクトに関連付けられている名前空間宣言を列挙します。

戻り値
Array — Namespace オブジェクトの配列です。

関連項目



The following example outputs the namespace declarations of an XML object:
 var xml:XML = <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/">

            <!-- ... -->
            
        </rdf:RDF>;
                    
for (var i:uint = 0; i < xml.namespaceDeclarations().length; i++) { var ns:Namespace = xml.namespaceDeclarations()[i]; var prefix:String = ns.prefix; if (prefix == "") { prefix = "(default)"; } trace(prefix + ":" , ns.uri); } 
The trace() output is the following:
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#  dc: http://purl.org/dc/elements/1.1/  (default): http://purl.org/rss/1.0/


nodeKind()メソッド 
AS3 function nodeKind():String

ノードのタイプ (テキスト、コメント、処理命令、属性、またはエレメント) を指定します。

戻り値
String — 使用するノードタイプです。

関連項目



This example traces all five node types:
 XML.ignoreComments = false; XML.ignoreProcessingInstructions = false;

var xml:XML = <example id="10"> <!-- this is a comment --> <?test this is a pi ?> and some text </example>;

trace (xml.nodeKind()); // element trace (xml.children()[0].nodeKind()); // comment trace (xml.children()[1].nodeKind()); // processing-instruction trace (xml.children()[2].nodeKind()); // text trace (xml.@id[0].nodeKind()); // attribute

normalize()メソッド 
AS3 function normalize():XML

XML オブジェクトとすべての子孫の XML オブジェクトについて、隣接するテキストノードを結合し、空のテキストノードを削除します。

戻り値
XML — 結果として作成される、正規化された XML オブジェクトです。

関連項目



The following example shows the effect of calling the normalize() method:
 var xml:XML = <body></body>; xml.appendChild("hello"); xml.appendChild(" world"); trace(xml.children().length()); // 2 xml.normalize(); trace(xml.children().length()); // 1

parent()メソッド 
AS3 function parent():*

XML オブジェクの親を返します。XML オブジェクトに親がない場合、メソッドは、undefined を返します。

戻り値
* — 親 XML オブジェクトです。String または null のいずれかを返します。

関連項目



The following example uses the parent() method to identify the parent element of a specific element in an XML structure:
 var xml:XML = <body> <p id="p1">Hello</p> <p id="p2">Test: <ul> <li>1</li> <li>2</li> </ul> </p> </body>; var node:XML = xml.p.ul.(li.contains("1"))[0]; // == <ul> ... </ul> trace(node.parent().@id); // p2

prependChild()メソッド 
AS3 function prependChild(value:Object):XML

指定された child オブジェクトのコピーを、このエレメント内の既存のすべての XML プロパティの前に挿入します。

XML ノードを削除するには、delete (XML) 演算子を使用します。

パラメータ
value:Object — 挿入するオブジェクトです。

戻り値
XML — 結果として作成される XML オブジェクトです。

関連項目



The following example uses the prependChild() method to add an element to the begining of a child list of an XML object:
 var xml:XML = <body> <p>hello</p> </body>;
        
xml.prependChild(<p>world</p>); trace(xml.p[0].toXMLString()); // <p>world</p> trace(xml.p[1].toXMLString()); // <p>hello</p>

processingInstructions()メソッド 
AS3 function processingInstructions(name:String = "*"):XMLList

name パラメータを指定した場合、その name を持つ処理命令を含む XML オブジェクトのすべての子を列挙します。パラメータを指定しなかった場合、メソッドは任意の処理命令を含む XML オブジェクトのすべての子を列挙します。

パラメータ
name:String (default = "*") — 照合する処理命令の名前です。

戻り値
XMLList — 一致する子オブジェクトのリストです。

関連項目



The following example uses the processingInstructions() method to get an array of processing instructions for an XML object:
 XML.ignoreProcessingInstructions = false; var xml:XML = <body> foo <?xml-stylesheet href="headlines.css" type="text/css" ?> <?instructionX ?>
            
    </body>;

trace(xml.processingInstructions().length()); // 2 trace(xml.processingInstructions()[0].name()); // xml-stylesheet

propertyIsEnumerable()メソッド 
AS3 function propertyIsEnumerable(p:String):Boolean

XML オブジェクトに適用される for..in ステートメント内で反復処理されるプロパティセット内に、プロパティ p があるかどうかを確認します。toString(p) == "0" の場合にのみ、true を返します。

パラメータ
p:String — チェックするプロパティです。

戻り値
Booleanfor..in ステートメント内でプロパティを反復処理できる場合は true、それ以外の場合は false を返します。

関連項目



The following example shows that, for an XML object, the propertyNameIsEnumerable() method returns a value of true only for the value 0; whereas for an XMLList object, the return value is true for each valid index value for the XMLList object:
 var xml:XML = <body> <p>Hello</p> <p>World</p> </body>;

trace(xml.propertyIsEnumerable(0)); // true trace(xml.propertyIsEnumerable(1)); // false

for (var propertyName:String in xml) { trace(xml[propertyName]); }

var list:XMLList = xml.p; trace(list.propertyIsEnumerable(0)); // true trace(list.propertyIsEnumerable(1)); // true trace(list.propertyIsEnumerable(2)); // false

for (var propertyName:String in list) { trace(list[propertyName]); }

removeNamespace()メソッド 
AS3 function removeNamespace(ns:Namespace):XML

このオブジェクトとすべての子孫に指定された名前空間を削除します。名前空間がオブジェクトの修飾名またはオブジェクトの属性の修飾名によって参照されている場合、removeNamespaces() メソッドは名前空間を削除しません。

パラメータ
ns:Namespace — 削除する名前空間です。

戻り値
XML — 結果として作成される XML オブジェクトのコピーです。

関連項目



The following example shows how to remove a namespace declaration from an XML object:
 var xml:XML = <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/">
    
        <!-- ... -->
        
    </rdf:RDF>;

trace(xml.namespaceDeclarations().length); // 3 trace(xml.namespaceDeclarations()[0] is String); // var dc:Namespace = xml.namespace("dc"); xml.removeNamespace(dc); trace(xml.namespaceDeclarations().length); // 2

replace()メソッド 
AS3 function replace(propertyName:Object, value:XML):XML

propertyName パラメータで指定されたプロパティを、指定された value パラメータに置き換えます。propertyName に一致するプロパティがない場合、XML オブジェクトは変更されません。

パラメータ
propertyName:Object — 数値、XML エレメントセットの無修飾名、XML エレメントセットの修飾名、またはアスタリスクワイルドカード ("*") を使用できます。無修飾名は、デフォルトの名前空間内での XML エレメントの識別に使用します。
 
value:XML — 置換する値です。この値には、XML オブジェクト、XMLList オブジェクト、または toString() で変換可能な値を使用できます。

戻り値
XML — 一致するプロパティが置き換えられた、結果として作成される XML オブジェクトです。

関連項目



The following example illustrates calling the replace() method with an integer as the first parameter:
 var xml:XML = <body> <p>Hello</p> <p>World</p> <hr/> </body>;

xml.replace(1, <p>Bob</p>); trace(xml); 
This results in the following trace() output:
  <body>      <p>Hello</p>      <p>Bob</p>      <hr/>  </body>  


The following example calls replace() method with a string as the first parameter:
 var xml:XML = <body> <p>Hello</p> <p>World</p> <hr/> </body>;

xml.replace("p", <p>Hi</p>); trace(xml); 
This results in the following trace() output:
  <body>      <p>Hi</p>      <hr/>  </body>;  


The following example illustrates calling the replace() method with a QName as the first parameter:
 var xml:XML = <ns:body xmlns:ns = "myNS"> <ns:p>Hello</ns:p> <ns:p>World</ns:p> <hr/> </ns:body>;

var qname:QName = new QName("myNS", "p"); xml.replace(qname, <p>Bob</p>); trace(xml);

This results in the following trace() output:
  <ns:body xmlns:ns = "myNS">      <p>Bob</p>      <hr/>  </ns:body>  


The following example illustrates calling the replace() method with the string "" as the first parameter:
 var xml:XML = <body> <p>Hello</p> <p>World</p> <hr/> </body>;

xml.replace("*", <img src = "hello.jpg"/>); trace(xml); 
This results in the following trace() output:
  <body>      <img src="hello.jpg"/>  </body>  


setChildren()メソッド 
AS3 function setChildren(value:Object):XML

XML オブジェクトの子プロパティを、value パラメータで指定された XML プロパティのセットに置き換えます。

パラメータ
value:Object — 置き換えに使用する XML プロパティです。単一の XML オブジェクト、または XMLList オブジェクトにすることができます。

戻り値
XML — 結果として作成される XML オブジェクトです。

関連項目



The following example illustrates calling the setChildren() method, first using an XML object as the parameter, and then using an XMLList object as the parameter:
 var xml:XML = <body> <p>Hello</p> <p>World</p> </body>;

var list:XMLList = xml.p;

xml.setChildren(<p>hello</p>); trace(xml);

//    <body> //        <p>hello</p> //    </body>

xml.setChildren(list); trace(xml);

//    <body> //        <p>Hello</p> //        <p>World</p> //    </body>

setLocalName()メソッド 
AS3 function setLocalName(name:String):void

XML オブジェクトのローカル名を、指定された name パラメータに変更します。

パラメータ
name:String — ローカル名に置き換える名前です。

関連項目



The following example uses the setLocalName() method to change the local name of an XML element:
 var xml:XML = <ns:item xmlns:ns="http://example.com"> toothbrush </ns:item>;
    
xml.setLocalName("orderItem"); trace(xml.toXMLString()); // <ns:orderItem xmlns:ns="http://example.com">toothbrush</ns:orderItem>

setName()メソッド 
AS3 function setName(name:String):void

XML オブジェクトの名前を、指定された修飾名または属性名に設定します。

パラメータ
name:String — オブジェクトの新しい名前です。

関連項目



The following example uses the setName() method to change the name of an XML element:
 var xml:XML = <item> toothbrush </item>;
    
xml.setName("orderItem"); trace(xml.toXMLString()); // <orderItem>toothbrush</orderItem>

setNamespace()メソッド 
AS3 function setNamespace(ns:Namespace):void

XML オブジェクトに関連付けられている名前空間を設定します。

パラメータ
ns:Namespace — 新しい名前空間です。

関連項目



The following example uses the soap namespace defined in one XML object and applies it to the namespace of another XML object (xml2):
 var xml1:XML = <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <!-- ... --> </soap:Envelope>; var ns:Namespace = xml1.namespace("soap");

var xml2:XML = <Envelope> <Body/> </Envelope>;
    
xml2.setNamespace(ns);

trace(xml2); 

setSettings()メソッド 
AS3 static function setSettings(... rest):void

XML プロパティ ignoreCommentsignoreProcessingInstructionsignoreWhitespaceprettyIndent、および prettyPrinting の値を設定します。 デフォルト設定は次のとおりです。デフォルト設定は、setObj パラメータが指定されていない場合に適用されます。

メモ : このメソッドは XML クラスのインスタンスには適用しません。コード XML.setSettings() のように、XML に適用します。

パラメータ
... rest — 次の各プロパティを持つオブジェクトです。
  • ignoreComments
  • ignoreProcessingInstructions
  • ignoreWhitespace
  • prettyIndent
  • prettyPrinting

関連項目



The following example shows: how to apply some custom settings (for including comments and processing instructions) prior to setting an XML object; how to then revert back to the default settings before setting another XML object; and then how to set the custom settings again (for setting any more XML objects):
 XML.ignoreComments = false; XML.ignoreProcessingInstructions = false; var customSettings:Object = XML.settings();

var xml1:XML = <foo> <!-- comment --> <?instruction ?> </foo>; trace(xml1.toXMLString()); //    <foo> //        <!-- comment --> //         <?instruction ?> //    </foo>

XML.setSettings(XML.defaultSettings()); var xml2:XML = <foo> <!-- comment --> <?instruction ?> </foo>; trace(xml2.toXMLString());

settings()メソッド 
AS3 static function settings():Object

プロパティ ignoreCommentsignoreProcessingInstructionsignoreWhitespaceprettyIndent、および prettyPrinting を取得します。

戻り値
Object — 次の XML プロパティを持つオブジェクトです。
  • ignoreComments
  • ignoreProcessingInstructions
  • ignoreWhitespace
  • prettyIndent
  • prettyPrinting

関連項目



The following example shows: how to apply some custom settings (for including comments and processing instructions) prior to setting an XML object; how to then revert back to the default settings before setting another XML object; and then how to set the custom settings again (for setting any more XML objects):
 XML.ignoreComments = false; XML.ignoreProcessingInstructions = false; var customSettings:Object = XML.settings();

var xml1:XML = <foo> <!-- comment --> <?instruction ?> </foo>; trace(xml1.toXMLString()); //    <foo> //        <!-- comment --> //         <?instruction ?> //    </foo>

XML.setSettings(XML.defaultSettings()); var xml2:XML = <foo> <!-- comment --> <?instruction ?> </foo>; trace(xml2.toXMLString());

text()メソッド 
AS3 function text():XMLList

XML テキストノードを表す XML オブジェクトのすべての XML プロパティの XMLList オブジェクトを返します。

戻り値
XMLList — プロパティのリストです。

関連項目



The following example uses the text() method to get the text nodes of an XML object:
 var xml:XML = <body> text1 <hr/> text2 </body>; trace(xml.text()[0]); // text1 trace(xml.text()[1]); // text2

toString()メソッド 
AS3 function toString():String

XML オブジェクトのストリング表現を返します。この変換の規則は、XML オブジェクトに単純内容が含まれるか、複合内容が含まれるかによって決まります。

XML オブジェクト全体を毎回返すには、toXMLString() を使用します。

戻り値
String — XML オブジェクトのストリング表現です。

関連項目



The following example shows what the toString() method returns when the XML object has simple content:
 var test:XML = <type name="Joe">example</type>; trace(test.toString()); //example

The following example shows what the toString() method returns when the XML object has complex content:
 var test:XML = <type name="Joe"> <base name="Bob"></base> example </type>; trace(test.toString()); // <type name="Joe"> // <base name="Bob"/> // example // </type>

toXMLString()メソッド 
AS3 function toXMLString():String

XML オブジェクトのストリング表現を返します。toString() メソッドとは異なり、toXMLString() メソッドは、XML オブジェクトに単純内容が含まれるか、複合内容が含まれるかに関係なく、常に XML オブジェクトの開始タグ、属性、および終了タグを返します。toString() メソッドは、単純内容を持つ XML オブジェクトの開始タグ、属性、および終了タグを削除します。

戻り値
String — XML オブジェクトのストリング表現です。

関連項目



The following example shows the difference between using the toString() method (which is applied to all parameters of a trace() method, by default) and using the toXMLString() method:
 var xml:XML = <p>hello</p>; trace(xml); // hello trace(xml.toXMLString()); // <p>hello</p>

valueOf()メソッド 
AS3 function valueOf():XML

XML オブジェクトを返します。

戻り値
XML — XML インスタンスのプリミティブ値です。

関連項目



The following example shows that the value returned by the valueOf() method is the same as the source XML object:
 var xml:XML = <p>hello</p>; trace(xml.valueOf() === xml); // true


The following example first creates an XML variable and adds nodes to it. Then XML properties are used to find and print XML nodes. Notice that the "at" (@) symbol is used in several of the trace() calls to locate information by attribute name.
 package { import flash.display.Sprite;

    public class XmlExample extends Sprite { public function XmlExample() { var employees:XML = <employees> <employee ssn="123-123-1234"> <name first="John" last="Doe"/> <address> <street>11 Main St.</street> <city>San Francisco</city> <state>CA</state> <zip>98765</zip> </address> </employee> <employee ssn="789-789-7890"> <name first="Mary" last="Roe"/> <address> <street>99 Broad St.</street> <city>Newton</city> <state>MA</state> <zip>01234</zip> </address> </employee> </employees>;

            trace(employees.employee[0].address.zip);   // 98765

            trace(employees.employee[1].@ssn);          // 789-789-7890

            trace(employees.employee.name);             // <name first="John" last="Doe"/> // <name first="Mary" last="Roe"/>

            trace(employees..zip[0]);                   // 98765

            trace(employees..@ssn[1]);                  // 789-789-7890

            trace(employees..name);                     // <name first="John" last="Doe"/> // <name first="Mary" last="Roe"/>

            trace(employees.employee[0].address.*);     // <street>11 Main St.</street> // <city>San Francisco</city> // <state>CA</state> // <zip>98765</zip> var node:String = "zip"; trace(employees.employee[0].address[node]); // 98765
            
            var attribute:String = "ssn"; trace(employees.employee[1].@[attribute]);  // 789-789-7890
            
            for each (var num:XML in employees..@ssn) { trace(num);                             // 123-123-1234 }                                           // 789-789-7890
            
            var ssnToFind:String = "789-789-7890"; trace(employees.employee.(@ssn == ssnToFind).toXMLString()); // <employee ssn="789-789-7890"> // <name first="Mary" last="Roe"/> // <address> // <street>99 Broad St.</street> // <city>Newton</city> // <state>MA</state> // <zip>01234</zip> // </address> // </employee> } } }