# How to modify the code to import from external XML file?

**URL:** <https://forum.kirupa.com/t/how-to-modify-the-code-to-import-from-external-xml-file/330742>\
**Category:** flash\
**Created:** [March 8, 2013, 8:41pm UTC](https://forum.kirupa.com/t/how-to-modify-the-code-to-import-from-external-xml-file/330742 "2013-03-08T20:41:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![learner\_7n](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@learner\_7n](https://forum.kirupa.com/u/learner_7n)\
**Post date:** [March 8, 2013, 8:41pm UTC](https://forum.kirupa.com/t/how-to-modify-the-code-to-import-from-external-xml-file/330742/1 "2013-03-08T20:41:37Z")

</div>

Hi,  
How can I modify the following working code to get data from external XML file?

import fl.controls.DataGrid;  
import fl.controls.TextInput;  
import fl.controls.dataGridClasses.DataGridColumn;  
import fl.data.DataProvider;

var dp:DataProvider = new DataProvider();  
dp.addItem({item:“Asparagus”, price:0.53});  
dp.addItem({item:“Brussel Sprouts”, price:0.27});  
dp.addItem({item:“Cabbage”, price:0.04});  
dp.addItem({item:“Cauliflower”, price:0.16});

var itemTextInput:TextInput = new TextInput();  
itemTextInput.move(10, 10);  
itemTextInput.addEventListener(Event.CHANGE, changeHandler);  
addChild(itemTextInput);

var itemCol:DataGridColumn = new DataGridColumn(“item”);  
itemCol.headerText = “Vegetable:”;

var priceCol:DataGridColumn = new DataGridColumn(“price”);  
priceCol.headerText = “Price (per/lb):”;  
priceCol.labelFunction = priceLabelFunction;  
priceCol.sortOptions = Array.NUMERIC;

var myDataGrid:DataGrid = new DataGrid();  
myDataGrid.addColumn(itemCol);  
myDataGrid.addColumn(priceCol);  
myDataGrid.dataProvider = dp;  
myDataGrid.width = 200;  
myDataGrid.rowCount = myDataGrid.length;  
myDataGrid.move(10, 40);  
addChild(myDataGrid);

function priceLabelFunction(item:Object):String {  
return “$” + Number(item.price).toFixed(2);  
}

function changeHandler(event:Event):void {  
var arr:Array = dp.toArray();  
var filteredArr:Array = arr.filter(filterDataProvider);  
myDataGrid.dataProvider = new DataProvider(filteredArr);  
}

function filterDataProvider(obj:Object, idx:int, arr:Array):Boolean {  
var txt1:String = itemTextInput.text;  
var txt2:String = obj.item.substr(0, txt1.length);  
if (txt1.toLowerCase() == txt2.toLowerCase()) {  
return true;  
}  
return false;  
}

Because I have a lot of data which can be easily entered/edited.

Thanks for any help.
