2010-07-09 12 views
2

j'ai XMl commeComment renommer un attribut en XML?

<record id="1" name="CustomerInfo"> 
    <field name="id" index="1" type="String"/> 
</record> 

je veux renommer « nom » attribut « match de » comme

<record id="1" match="CustomerInfo"> 
    <field match="id" index="1" type="String"/> 
</record> 
+0

Pouvez-vous tester la méthode 'setName' et me dire si cela fonctionne? Je n'ai pas accès au compilateur Flash maintenant – Amarghosh

Répondre

0

Essayez setName method: Je ne l'ai pas utilisé, mais le docs dit que cela fonctionnera aussi sur les attributs.

var xml:XML = <record id="1" name="CustomerInfo"> 
       <field name="id" index="1" type="String"/> 
       </record>; 

[email protected][0].setName("match"); 
trace(xml.toXMLString()); 

[email protected][0].setName("match"); 
trace(xml.toXMLString()); 

Mise à jour: Il fonctionne en javascript Firefox e4x, il devrait fonctionner dans ActionScript aussi. Essayez ceci:

var xml:XML = <record id="1" name="CustomerInfo"> 
       <field name="id" index="1" type="String"/> 
       </record>; 

var names:XMLList = xml.descendants("@name");//all `name` attributes 
for(var i:Number = 0; i < names.length(); i++) 
{ 
    names[i].setName("match"); 
} 
trace(xml.toXMLString()); 
Questions connexes