Erik's blog

Code, notes, recipes, general musings

playing with e4x in firefox: iteratively appending xml elements

leave a comment »

prereq: firefox w/ firebug installed
note: if there is no pre-existing 'child' element, using '+=' operator will append 'child' to 'parent', not 'children'
1) put this code in an html file
2) run it in firefox
3) look for output in console
var names = ['julio','juan','jose'],
	xml = <parent>
for(var i = 0; i < names.length; i++) {
    //check for pre-existing 'child'
	if(xml.children.child){//if there, append
	 	xml.children.child += <child name={names&#91;i&#93;}/>;
	}else{//create initial 'child' element
		xml.children.child = <child name={names&#91;i&#93;}/>;

Written by Erik

May 21, 2009 at 7:35 pm

Posted in tutorial

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: