# XML & DataGrid - Flash 8

**URL:** <https://forum.kirupa.com/t/xml-datagrid-flash-8/259434>\
**Category:** flash\
**Created:** [May 5, 2008, 12:48pm UTC](https://forum.kirupa.com/t/xml-datagrid-flash-8/259434 "2008-05-05T12:48:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamSax](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@SamSax](https://forum.kirupa.com/u/SamSax)\
**Post date:** [May 5, 2008, 12:48pm UTC](https://forum.kirupa.com/t/xml-datagrid-flash-8/259434/1 "2008-05-05T12:48:48Z")

</div>

I’m having trouble writing the proper loop to parse an xml file and populate a DataGrid.

For those XML nodes that have children, I’m trying to place them as an array into a single field of the DataGrid’s column.

My XML is structured as follows:

```auto

<shows>
    <Presentations name="FirstPresentation" version="edited">
        <slide type="swf" loadSize="normal">FirstSlide.swf</slide>
        <slide type="swf" loadSize="scale">SecondSlide.swf</slide>
    </Presntations>
    <Presentations name="SecondPresentation" version="full">
        <slide type="swf" loadSize="full">Blue.swf</slide>
        <slide type="swf" loadSize="normal" >Red.swf</slide>
    </Presntations>
</shows>

```

What I am trying to end up with a DataGrid in the following format:[INDENT][SIZE=1]\*\*Presentation: \*\*[/SIZE]  
[SIZE=1]_FirstPresentation_[/SIZE]  
[SIZE=1]\*SecondtPresentation \*[/SIZE]

[SIZE=1] **Version:** [/SIZE]  
[SIZE=1]_edited_[/SIZE]  
[SIZE=1]_full_[/SIZE]

[SIZE=1] **Files:** [/SIZE]  
[SIZE=1]\*FirstSlide.swf, SecondSlide.swf \*[/SIZE]  
[SIZE=1]\*Blue.swf, Red.swf \*[/SIZE]

[SIZE=1] **type:** [/SIZE]  
[SIZE=1]_swf, swf_[/SIZE]  
[SIZE=1]_swf, swf_[/SIZE]

[SIZE=1] **LoadSize** [/SIZE]  
[SIZE=1]_normal, scale_[/SIZE]  
[SIZE=1]_full, normal_[/SIZE]  
[/INDENT]The **files** , **type** , and **LoadSize** fields would hold an array object of all childNodes and attributes for each Presentation node.

I was able to accomplish this in a similar app in which an additional DataGrid was first populated by parsing only the XML’s Presentation nodes into a list of presentation titles. Clicking on any one title would activate the following code and populate the second DataGrid - which is the one the user could sort through and edit.

```auto

//After loading & parsing XML file into the folling variable
//rawPresentations = this.firstChild.childNodes;
//And then populating a DataGrid with the name attribute of each Presentation node:
//
var fileArray = new Array();
var typeArray = new Array();
var loadSizeArray = new Array();

for (a = 0; a < rawPresentations.length; a++) {
    if (preSents[myIndex]["prezName"] == rawPresentations[a].attributes["presentName"]) {
        for (z = 0; z < rawPresentations[a].childNodes.length; z++) {
            fileArray.push(rawPresentations[a].childNodes[z].firstChild)
            typeArray.push(rawPresentations[a].childNodes[z].attributes["type"])
            loadSizeArray.push(rawPresentations[a].childNodes[z].attributes["loadSize"])
        } 
    selectedPresents.addItem({Name:rawPresentations[a].attributes["presentName"], Version: rawPresentations[a].attributes["version"], files: fileArray, type: typeArray, loadSize: loadSizeArray})
    delete fileArray
    delete typeArray
    delete loadSizeArray
    }
} 
myDataGrid.dataProvider = selectedPresents

```

The above code only works by individually parsing and adding each presentation element. What I need now is to populate a DataGrid with the entire contents of the XML file in one shot.

Any help very much appreciate as I have a deadline tomorrow - Thanks!

[SIZE=1]\*[SIZE=1][SIZE=2]

[/SIZE]  
[/SIZE]

\*[/SIZE]
