Erik's blog

Code, notes, recipes, general musings

playing with e4x in firefox: iteration with a for loop

leave a comment »

<script>
/*
ref: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Processing_XML_with_E4X
ref: http://bit.ly/y8udj
prereq: firefox w/ firebug installed
1) put this code in an html file
2) run it in firefox
3) look for output in console
*/
var xml = <parent>
	<children>
		<child name="julio"/>
		<child name="juan"/>
		<child name="jose"/>
	</children>
</parent>;
for (var i = 0; i < xml.children.child.length(); i++) {//note: 'parent' is not the root var name
    console.log(xml.children.child&#91;i&#93;.@name);
}
</script>
Advertisements

Written by Erik

May 21, 2009 at 7:14 pm

Posted in tutorial

Tagged with , ,

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: