In the following code, how do I pull the <pubDate> element of my XML file into my Flex application? I am a newb to Flex and have read the XML docs but still do not fully understand how to traverse an XML document using e4x.
I essentially want to pull the pubDate and list that date in the Sections panel and echo the label as "Sections for {pubDate}" but I have no idea how to do it.
Any help would be appreciated.
XML:
Code:
<tearsheets>
<pubDate>Saturday, July 14, 2007</pubDate>
<section aname="A">
<page aname="02" date="20070714" sectionID="A" />
<page aname="03" date="20070714" sectionID="A" />
</section>
</tearsheets>
</section>
MXML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*"
layout="horizontal"
creationComplete="buildList.send();">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
[Bindable]
private var sectionList:XMLList;
private function buildListHandler(event:ResultEvent):void
{
sectionList = event.result..section;
}
private function populateForm(event:Event):void
{
var node:XML=event.target.selectedItem;
if(node.@pdf != undefined)
{
sectionID.text = node.@sectionID;
pageNumber.text = node.@aname;
theForm.visible = true;
}
else
{
theForm.visible = false;
sectionID.text = "";
pageNumber.text = "";
}
}
]]>
</mx:Script>
<mx:HTTPService
id="buildList"
url="Tearsheets.xml"
showBusyCursor="true"
result="buildListHandler(event)"
resultFormat="e4x"/>
<mx:Panel id="leftPanel" title="Sections" width="100%" height="{centerPanel.height}">
<mx:Tree id="sectionsTree"
dataProvider="{sectionList}"
labelField="@aname"
width="100%"
height="100%"
borderThickness="0"
change="populateForm(event)"/>
</mx:Panel>
<mx:Panel id="centerPanel" title="Page Details" width="100%" height="{theForm.height+100}">
<mx:Form id="theForm" visible="false">
<mx:FormHeading/>
<mx:FormItem label="Section">
<mx:TextInput id="sectionID"/>
</mx:FormItem>
<mx:FormItem label="Page">
<mx:TextInput id="pageNumber"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:Application>