The XMLShortcuts component enables shortcut access to All XML nodes.

Biggest advantage of using XML shortcuts is it can be easily added to existing projects with out any modification. Simply drag and drop the component from components window to the stage and then delete it from stage (let it stay in the library).

Available Shortcuts:

Property Description
childNode Get the first child node with the specified node name
childNode_index Get the specific child node with the specified node name and index
$childNode Get all the child nodes with the specified node name as an array.
_attribute Get the value for specific attribute name
__text Get the text node
rootNode Access the root node of XML from any node using this shortcut

Note: Replace childNode, index, and attribute with their respective values. See the example below

my_xml:

<english>
 <a word="apple">a for apple</a>
 <a word="Arul">a for Arul</a>
 <b word="ball">b for ball</b>
 <b word="bee">b for bee</b>
 <c word="cat">c for cat</c>
 <c word="cow">c for cow</c>
</english>

Using the XML above

Untitled Document

Property Example Trace output
childNode
trace(my_xml.english.a)
<a word=”apple”>a for apple</a>
childNode_index
trace(my_xml.english.a_1)
<a word=”Arul”>a for Arul</a>
$childNode
trace(my_xml.english.$b)
<b word=”ball”>b for ball</b>,
<b word=”bee”>b for bee</b>
_attribute
trace(my_xml.english.c._word)
cat
__text
trace(my_xml.english.c.__text)
c for cat
rootNode
trace(my_xml.english.c.rootNode instanceof XML)
true

Caution: Avoid data type declaration while initializing XML and XMLNode
for example the following code will throw a compiler error “There is no property with the name ‘x'”

[cc lang=”actionscript3″]var myXML:XML = new XML (“<x><y/><x>”); trace (myXML.x); [/cc]

Where as the following code works fine
[cc lang=”actionscript3″]var myXML = new XML (“<x><y/><x>”); trace (myXML.x);

[/cc]


Hope it is of some use to everyone using flash and xml in their day to day life. Feel free to express your views in the comment, I will be glad to hear from you 🙂

Download: XMLShortcuts.mxp