Article written

  • on 13.10.2009
  • at 11:07 PM
  • by mich

Dynamic XML definitions 0

Oct13

Something that I haven’t noticed for a long time are dynamic xml definitions. What it is; Its a very easy way to construct xml with dynamic content. Here is a short example:

var nodeValue:String = "bis naii";
var attributeValue:String = "mich";
var xml:XML = <speech speaker={attributeValue}>{nodeValue}</speech>;
trace( xml ); // <speech speaker="mich">bis naii</speech>

The {} braces are replaced by the variable value. You can also place more complex stuff inside these curly braces. Here is another example:

var xml:XML = <root />
for ( var i:Number = 0; i < 3; i++ ) {
    xml.appendChild( <child>{"content: " + ( i + 1 )}</child> );
}
/**
 * gives:
 * <root>
 * <child>content: 1</child>
 * <child>content: 2</child>
 * <child>content: 3</child>
 * </root>
 */

In some situations this way of constructing an xml structure is very practical….

For more infos check senocular’s page about XML

subscribe to comments RSS

There are no comments for this post

Please, feel free to post your own comment

* these are required fields

Developed by Dariusz Siedlecki and brought to you by FreebiesDock.com