PDA

View Full Version : Writing Variables into XML



e_owen
March 8th, 2010, 10:25 AM
How can I write variables into new XML? I need to take variables and write them into new XML but that I am getting is the name of the variable I am using, not the value.



var _label:String = _set.attribute( "containing" ).toString();
_subMenuItems.appendChild( XML(<item><label>_label</label></item> ) );

//
// Outputs
<item><label>_label</label></item>

ven
March 8th, 2010, 11:17 AM
var label:String = "A label!";
var xml:XML = <someXML/>;

// One funky way to do it, is just typing E4X
xml.item.label = label;

// Another way to do it, like you did (but remember the curly braces)
var item:XML = <item><label>{label}</label></item>;
xml.appendChild(item);

trace(xml.toString());

e_owen
March 8th, 2010, 01:15 PM
Perfect!

Thanks guy.