I'm trying to parse some xml in AS3, but the nodes I'm trying to call up are named keywords like 'name' and 'object'. Can I escape these words somehow?
views:
30answers:
2
A:
As MrKishi already pointed out, these keywords are not always a problem, so you can use regular syntax.
There some cases, though, were valid xml tag and attribute names are not valid actionscript (off the top of my head, this happens when you have hyphens in your xml structure).
A workaround is using square brackets and/or more verbose method calls.
var xml:XML =
<xml>
<node-with-hyphens attr-with-hyphens="123">Object 1</node-with-hyphens>
</xml>;
trace(xml["node-with-hyphens"]);
trace(xml.child("node-with-hyphens"));
trace(xml["node-with-hyphens"].attribute("attr-with-hyphens"));
Juan Pablo Califano
2010-06-19 02:06:33