View Full Version : XML parsing problem

08-02-2007, 03:09 PM
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.


<pubDate>Saturday, July 14, 2007</pubDate>
<section aname="A">
<page aname="02" date="20070714" sectionID="A" />
<page aname="03" date="20070714" sectionID="A" />


<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"






import mx.rpc.events.ResultEvent;


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;




theForm.visible = false;

sectionID.text = "";

pageNumber.text = "";











<mx:Panel id="leftPanel" title="Sections" width="100%" height="{centerPanel.height}">

<mx:Tree id="sectionsTree"








<mx:Panel id="centerPanel" title="Page Details" width="100%" height="{theForm.height+100}">

<mx:Form id="theForm" visible="false">


<mx:FormItem label="Section">

<mx:TextInput id="sectionID"/>


<mx:FormItem label="Page">

<mx:TextInput id="pageNumber"/>





08-02-2007, 05:23 PM
You have to use toString() to access XML data (non attribute).

Like: myXML.pubDate.toString()

Is this the issue you're having, or is the issue about knowing when to access it?


08-02-2007, 05:35 PM
I am having problems in general pulling any attributes from an XML file loaded from an HTTPService. I have read all the docs, have watched several training videos, and still do not fully understand all the ways to load in XML data into a Flex project.

I simply want to echo the pubDate element into a Panel's title field.

Thanks for your help.

08-03-2007, 01:02 AM
Well your XML var looks like it's called sectionList, so you would do the same as above except use that instead of myXML. To get it into your panel, you could probably set up some kind of binding to the XML, but I am not very familiar with HTTPService. I've always preferred the AS alternative.

Until someone else can give you a better solution, you can create a Bindable string which the panel title populates from. When your XML is loaded, assign sectionList.pubDate.toString() to it.

Hope this helps,

Jim Freer
08-04-2007, 12:38 PM
A lot of the problems I see in this forum dealing with E4X are rooted in the confusion between an XML object and an XMLList object. I think the architects of E4X had good intentions, butÖ

Itís hard to help you with what you have provided. The snippet of XML doesnít give enough information, but along with that itís hard to tell what the specific object (XML or XMLList) contains when you are trying to extract pubDate. Also whereas aname is an attribute, the date in element pubDate is a text node.

It would a lot more efficient if we could ask the question after reviewing the answer.