# XML to Array

**URL:** <https://forum.kirupa.com/t/xml-to-array/163496>\
**Category:** flash\
**Created:** [September 22, 2005, 8:16pm UTC](https://forum.kirupa.com/t/xml-to-array/163496 "2005-09-22T20:16:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvie](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@sylvie](https://forum.kirupa.com/u/sylvie)\
**Post date:** [September 22, 2005, 8:16pm UTC](https://forum.kirupa.com/t/xml-to-array/163496/1 "2005-09-22T20:16:50Z")

</div>

Hello,

I need your help.

/\* xml file\*/  
\<?xml version=“1.0” encoding=“ISO-8859-1”?\>  
\<data\>  
\<news\>  
\<newstitle\>title+1\</newstitle\>  
\<newsitem\>text+1\</newsitem\>  
\<newsurl\>\</newsurl\>  
\</news\>  
\<news\>  
\<newstitle\>title+2\</newstitle\>  
\<newsitem\>text+2\</newsitem\>  
\<newsurl\>\</newsurl\>  
\</news\>  
\<news\>  
\<newstitle\>title+3\</newstitle\>  
\<newsitem\>text+3\</newsitem\>  
\<newsurl\>\</newsurl\>  
\</news\>  
\</data\>

In the script below I parse the XML file to an array:

class controlClass  
{  
var firstChild;  
function controlClass()  
{  
}  
function createXMLArray(XMLobj, URL)  
{  
\_root[XMLobj] = new Array({});  
var xmlXML = new XML();  
xmlXML.ignoreWhite = true;  
xmlXML.onLoad = function (success)  
{  
if (success)  
{  
var l1 = firstChild.childNodes;  
for (var l2 in l1)  
{  
\_root[XMLobj][l2] = {};  
var l3 = l1[l2].childNodes;  
for (var l4 in l3)  
{  
\_root[XMLobj][l2][l3[l4].nodeName] = l3[l4].firstChild;  
}  
}  
}  
};  
xmlXML.load(URL, xmlXML, “POST”);  
}  
}

I call the createXMLArray from the following main program (.fla):

\_global.Control = new controlClass();  
Control.createXMLArray(“newsXML”, “news.xml”);

This works.

What I am unable to do is to access the data in newsXML array, especially those related to a particular nodename, writing for example:

trace(\_root.newsXML[0].newstitle);

Problem of variable scope or anything else?

Your help is welcome!

Sylvie
