documentation flash xml idmap

Vous êtes ici: Les articles techniques » documentation » Eléments du langage ActionScript » XML » idMap (XML.idMap, propriété)

idMap (XML.idMap, propriété)

 
public idMap : Object

Objet contenant les nÅ“uds du fichier XML auxquels un attribut id a été attribué. Les noms des propriétés de l’objet (contenant un nÅ“ud chacun) correspondent aux valeurs des attributs id.

Considérez l’objet XML suivant :

 <employee id='41'>
 <name>
 John Doe
 </name>
 <address>
 601 Townsend St.
 </address>
 </employee>
 
 <employee id='42'>
 <name>
 Jane Q. Public
 </name>
 </employee>
 <department id="IT">
 Information Technology
 </department>

Dans cet exemple, la propriété idMap de cet objet XML est un Objet avec trois propriétés : 41, 42 et IT. Chacune de ces propriétés est un XMLNode avec la valeur id correspondante. Par exemple, la propriété IT de l’objet idMap est ce nÅ“ud :

 <department id="IT">
 Information Technology
 </department>

Vous devez utiliser la méthode parse() sur l’objet XML pour la propriété idMap à être instancié.

Si plus d’un XMLNode a la même valeur id, la propriété correspondante de l’objet idNode est celle du dernier nÅ“ud analysé, de la manière suivante :

var x1:XML = new XML("<a id='1'><b id='2' /><c id='1' /></a>");
x2 = new XML();
x2.parseXML(x1);
trace (x2.idMap['1']);

L’exemple suivant donnera en sortie le nÅ“ud <c> :

 <c id='1' />

Disponibilité : ActionScript 1.0 ; Flash Player 8

Exemple

Vous pouvez créer un texte fichier nommé idMapTest.xml contenant le texte suivant .

 <?xml version="1.0"?> 
 <doc xml:base="http://example.org/today/" xmlns:xlink="http://www.w3.org/1999/xlink"> 
 <head> 
 <title>Virtual Library</title> 
 </head> 
 <body> 
 <paragraph id="linkP1">See <link xlink:type="simple" xlink:href="new.xml">what's 
 new</link>!</paragraph> 
 <paragraph>Check out the hot picks of the day!</paragraph> 
 <olist xml:base="/hotpicks/"> 
 <item> 
 <link id="foo" xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link> 
 </item> 
 <item> 
 <link id="bar" xlink:type="simple" xlink:href="pick2.xml">Hot Pick #2</link> 
 </item> 
 <item> 
 <link xlink:type="simple" xlink:href="pick3.xml">Hot Pick #3</link> 
 </item> 
 </olist>
 </body> 
 </doc>

Vous pouvez ensuite créer un fichier SWF dans le même répertoire que le fichier XML. Vous pouvez inclure le script suivant dans le SWF.

var readXML = new XML();
readXML.load("idMapTest.xml");
readXML.onLoad = function(success) {
     myXML = new XML();
     myXML.parseXML(readXML); 
     for (var x in myXML.idMap){
          trace('idMap.' + x + " = " + newline + myXML.idMap[x]);
          trace('____________' + newline);
     }
}

Lorsque vous testez le fichier SWF, la sortie suivante est générée.

 idMap.bar = 
 <link id="bar" xlink:type="simple" xlink:href="pick2.xml">Hot Pick #2</link>
 ____________
 
 idMap.foo = 
 <link id="foo" xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link>
 ____________
 
 idMap.linkP1 = 
 <paragraph id="linkP1">See <link xlink:type="simple" xlink:href="new.xml">what's 
 
 new</link>!</paragraph>
 ____________



veille
inscrits inscrits ! Compensation à la rédaction
  • Inscription au wiki
  • Connexion

vod