/* I start with this: */
<Report>
<prop1>4</prop1>
<prop2>2255</prop2>
<prop3>true</prop3>
<prop4>false</prop4>
<prop5>true</prop5>
</Report>
/* I want this result (change the value of node "prop5"): */
<Report>
<prop1>4</prop1>
<prop2>2255</prop2>
<prop3>true</prop3>
<prop4>false</prop4>
<prop5>false</prop5>
</Report>
/* I tried this: */
var reportXML:XML =
<Report>
<prop1>4</prop1>
<prop2>2255</prop2>
<prop3>true</prop3>
<prop4>false</prop4>
<prop5>true</prop5>
</Report>;
var myArray:Array = [{xmlNodeName: "prop5", value: false}];
for each (var item:Object in myArray)
{
report.xml[item.xmlNodeName] = item.value.toString();
}
/* But this just adds a new node, resulting in this: */
<Report>
<prop1>4</prop1>
<prop2>2255</prop2>
<prop3>true</prop3>
<prop4>false</prop4>
<prop5>true</prop5>
<prop5>false</prop5>
</Report>;
最佳答案
这似乎正是你想要的。只是你的代码有点错别字。
var reportXML:XML =
<Report>
<prop1>4</prop1>
<prop2>2255</prop2>
<prop3>true</prop3>
<prop4>false</prop4>
<prop5>true</prop5>
</Report>;
var myArray:Array = [{xmlNodeName: "prop5", value: false}];
for each (var item:Object in myArray)
{
reportXML[item.xmlNodeName] = item.value.toString();
}
trace(reportXML);