Submitted by Ric (not verified) on 4 May 2007 - 9:02am.
Greetings:
I'm coming from a Mozilla/JavaScript 1.7 environment; so E4X is important for me as well. I have the same concern about using VARIABLES. I would like to know the correct synax for accessing ELEMENTS using a VARIABLE.
One classic need: to check for the existance of a particular ELEMENT using a VARIABLE that contains the ELEMENT's name.
After fiddling with your example and remembering about not using the '.' before the square brackets, I came across the following syntax:
var attr = "hairColor";
var val = "blond";
var creature = 'animal';
var x=...
var y = x[creature].(@[attr]==val).fav.color.@name);
Here, y = green.
Joel, you read my mind!
Great article!
Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"
What is the correct syntax for an Element vs Attribute variable?
Greetings:
I'm coming from a Mozilla/JavaScript 1.7 environment; so E4X is important for me as well. I have the same concern about using VARIABLES. I would like to know the correct synax for accessing ELEMENTS using a VARIABLE.
One classic need: to check for the existance of a particular ELEMENT using a VARIABLE that contains the ELEMENT's name.
After fiddling with your example and remembering about not using the '.' before the square brackets, I came across the following syntax:
var attr = "hairColor";
var val = "blond";
var creature = 'animal';
var x=...
var y = x[creature].(@[attr]==val).fav.color.@name);
Here, y = green.
Joel, you read my mind!
Great article!
Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"