/* 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>;
views:
2971answers:
5
A:
Using E4X syntax in ActionScript 3 I guess that would be something like:
report.prop5[0] = false;
Christophe Herreman
2008-11-17 15:48:04
This didn't work either. This created a new node with a different namespace (the namespace was based on the name of the class I was in).
Eric Belair
2008-11-17 16:48:38
A:
I just verified that this works:
private var reportXML:XML =
<Report>
<prop1>4</prop1>
<prop2>2255</prop2>
<prop3>true</prop3>
<prop4>false</prop4>
<prop5>true</prop5>
</Report>;
private function changeXML():void {
reportXML.prop5[0] = 'false';
trace(reportXML.prop5); // traces 'false'
}
defmeta
2008-11-17 20:47:37
This still does not answer my original question. Look at my original example - I want this to be DYNAMIC. I have an Array of Objects that specify the nodes to be updated. My whole purpose in posting this is to find a way to not have to hardcode "prop5" into my application.
Eric Belair
2008-11-18 16:48:51
+1
A:
This seems to be doing exactly what you want. It's just your code with some typos fixed.
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);
Jesse Millikan
2008-12-02 05:17:31
I'll give you credit for this one.... I've got it working now. Both in pseudo code and real code. Thanks.
Eric Belair
2008-12-03 21:30:16
A:
Eric did you ever get a solution to this problem? I have the exact same problem, i create an xml (its in 1 namespace), then i get some data from another function and i want to edit this xml's nodes but it just adds other nodes with wrong namespace.
MartinD
2009-12-08 10:26:00
A:
if you only have the node you can go like this
var node:XML
inp = new textfield(style, node.text());
inp.addEventListener(TextEvent.TEXT_INPUT, change, false, 0, true);
addChild(inp);
private function change(e:TextEvent):void
{
XML(node.parent())[node.name()][node.childIndex()] = inp.text+e.text;
}
manu
2010-10-15 00:32:49