Saturday, March 27, 2010

Filtering XML File

Here is a synopsis of what I am attempting to accomplish (or
what I think I should do, I could be wrong):



I have my main MXML file with series of combobox menus, I
then have a MXML component that I created that consists of a data
grid and some graphs. In the component I have a HTTPService that
calls on the XML file I then want to assign the data from the XML
file to an ArrayCollection and filter the ArrayCollection based
upon selections that I made in my combobox menus, I then use the
Array Collection as the dataProvider for the charts and datagrids.
I have included my code here in this post for reference, along with
a sampling of what my XML file looks like. I have tried many things
to no avail to get this to work.



Note: I created the XML file from SQL Server



If anyone has a solution to the problem I would be
appreciative if you could share with me. Or if you have an idea of
a better process that would be good as well. Thank you all in
advance for your help.



Snippet From XML File (for security reasons I have changed
some of the data but the format is the same):



%26lt;?xml version=''1.0''?%26gt;

%26lt;ROOT%26gt;

%26lt;reference_ClicksCreativeYTD FUNDING_SOURCE=''Funding
Source'' DIVISION=''Division'' DMA=''DMA'' BUY_TYPE=''Buy Type''
CREATIVE_GROUP_1=''CG1'' DEL_IMPS=''####'' DEL_CLICKS=''####''
CTR=''####''/%26gt;

... (File continues on about 250 items)

%26lt;/ROOT%26gt;



MXML Code:



%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;

%26lt;mx:Panel xmlns:mx=''
http://www.adobe.com/2006/mxml''
creationComplete=''onCreationComplete()'' xmlns=''*'' layout=''absolute''
width=''490'' height=''364'' backgroundColor=''#ffffff''
borderColor=''#b4b4b4'' title=''Creative Strategy Vs. Message -
%26amp;lt;Dynamic Label%26amp;gt;'' fontWeight=''bold'' fontSize=''12''
fontFamily=''Arial''%26gt;

%26lt;mx:Script%26gt;

%26lt;![CDATA[



import mx.managers.PopUpManager;

import mx.core.IFlexDisplayObject;

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent;

import mx.rpc.events.InvokeEvent;

import mx.controls.Alert;

import mx.managers.CursorManager;

import mx.collections.ArrayCollection;



public var caller:DashLMGRevised;



[Bindable]

private var acCreative:ArrayCollection;



private function onCreationComplete():void

{

ClicksCreativeYTDXML.send();

}



private function onInvoke(event:InvokeEvent):void

{

CursorManager.setBusyCursor();

}



private function onResult(event:ResultEvent):void

{

acCreative = event.result.ROOT.reference_ClicksCreativeYTD;

acCreative.refresh();

acCreative.filterFunction = AryFilter;

colx.dataProvider = acCreative;

cols.dataProvider = acCreative;

line.dataProvider = acCreative;

dgCreateCompare.dataProvider = acCreative;

CursorManager.removeBusyCursor();

}



private function onFault(event:FaultEvent):void

{

Alert.show(event.fault.message);

CursorManager.removeBusyCursor();

}



public function AryFilter(item:Object):Boolean

{

var result:Boolean=false;



if ((item.DIVISION == caller.cbDivision.value) %26amp;%26amp;
(item.DMA == caller.cbDMA.value) %26amp;%26amp; (item.FUNDING_SOURCE ==
caller.Funding.value) %26amp;%26amp; (item.BUY_TYPE ==
caller.Strategy.value)) {

result=true;

}

return result;

}



private function showCreativeCompare():void

{

var
helpwindow:IFlexDisplayObject=PopUpManager.createPopUp(this,enlargeCreativeComp are,false);

}



private function updateCreateCompare():void

{

var
helpwindow:IFlexDisplayObject=PopUpManager.createPopUp(this,updateCreativeCompa re,false);


}

]]%26gt;

%26lt;/mx:Script%26gt;



%26lt;mx:HTTPService id=''ClicksCreativeYTDXML''
url=''ClicksCreativeYTD.xml'' invoke=''onInvoke(event)''
result=''onResult(event)'' fault=''onFault(event)''
resultFormat=''e4x''/%26gt;



%26lt;mx:Style source=''/Styles/JoshuaCSS.css'' /%26gt;

%26lt;mx:ViewStack x=''0'' y=''0'' id=''vsCreateCompare''
width=''100%'' height=''100%''%26gt;

%26lt;mx:VBox x=''0'' y=''0'' height=''100%''
id=''vbCreateCompareChart'' icon=''@Embed('icon_chart.png')''
width=''100%''%26gt;

%26lt;mx:ColumnChart id=''colClicksCreateYTD'' width=''100%''
height=''100%''%26gt;

%26lt;mx:horizontalAxis%26gt;

%26lt;mx:CategoryAxis id=''colx''
categoryField=''CREATIVE_GROUP_1''/%26gt;

%26lt;/mx:horizontalAxis%26gt;



%26lt;mx:verticalAxis%26gt;

%26lt;mx:LinearAxis minimum=''0'' maximum=''200000''/%26gt;

%26lt;/mx:verticalAxis%26gt;



%26lt;mx:series%26gt;

%26lt;mx:ColumnSeries id=''cols'' displayName=''Series 1''
yField=''DEL_IMPS'' xField=''CREATIVE_GROUP_1''/%26gt;

%26lt;/mx:series%26gt;



%26lt;mx:secondVerticalAxis%26gt;

%26lt;mx:LinearAxis minimum=''0'' maximum=''1''/%26gt;

%26lt;/mx:secondVerticalAxis%26gt;



%26lt;mx:secondVerticalAxisRenderer%26gt;

%26lt;mx:AxisRenderer placement=''left''
tickPlacement=''inside''/%26gt;

%26lt;/mx:secondVerticalAxisRenderer%26gt;



%26lt;mx:secondSeries%26gt;

%26lt;mx:ColumnSeries id=''line'' displayName=''Series 2''
yField=''CTR'' xField=''CREATIVE_GROUP_1''/%26gt;

%26lt;/mx:secondSeries%26gt;

%26lt;/mx:ColumnChart%26gt;

%26lt;/mx:VBox%26gt;

%26lt;mx:VBox x=''0'' y=''0'' height=''100%'' width=''100%''
id=''vbCreateCompare'' icon=''@Embed('icon_grid.png')''%26gt;

%26lt;mx:DataGrid width=''100%'' height=''100%''
id=''dgCreateCompare''%26gt;

%26lt;mx:columns%26gt;

%26lt;mx:DataGridColumn headerText=''Creative Group''
dataField=''CREATIVE_GROUP_1''/%26gt;

%26lt;mx:DataGridColumn headerText=''Delivered Clicks''
dataField=''DEL_CLICKS''/%26gt;

%26lt;mx:DataGridColumn headerText=''Delivered Impressions''
dataField=''DEL_IMPS''/%26gt;

%26lt;mx:DataGridColumn headerText=''Click Through Rate (CTR)''
dataField=''CTR''/%26gt;

%26lt;/mx:columns%26gt;

%26lt;/mx:DataGrid%26gt;

%26lt;/mx:VBox%26gt;

%26lt;/mx:ViewStack%26gt;

%26lt;mx:ControlBar y=''271'' id=''conbarCreateCompare''
verticalAlign=''middle'' width=''92'' height=''28''
horizontalAlign=''center''%26gt;

%26lt;mx:ToggleButtonBar dataProvider=''{vsCreateCompare}''
id=''toggleClicksCreateCompare'' width=''60'' height=''20'' fontSize=''10''
fontWeight=''bold''/%26gt;

%26lt;mx:Button label=''Enlarge'' width=''60''
id=''btnEnlargeInsights'' click=''showCreativeCompare();'' height=''20''
fontSize=''10'' fontWeight=''bold''/%26gt;

%26lt;mx:Button label=''Update'' id=''btnUpdateInsights''
width=''60'' click=''updateCreateCompare();'' height=''20'' fontSize=''10''
fontWeight=''bold''/%26gt;

%26lt;/mx:ControlBar%26gt;



%26lt;/mx:Panel%26gt;



Again thank you all for your help.

No comments:

Post a Comment