2010-07-09 73 views
2

我对XML喜欢如何重命名XML中的属性?

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

我想重命名“”属性“比赛”像

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

你可以测试'setName'方法并告诉我它是否有效吗?我现在无法访问Flash编译器 – Amarghosh 2010-07-09 10:49:23

回答

0

尝试setName method:我没有使用它,但是docs表示它也可以用于属性。

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()); 

更新:在Firefox的JavaScript E4X,因此它应该在ActionScript工作了。试试这个:

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());