Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-02-2007, 03:09 PM   #1
Registered User
Join Date: Jan 2006
Posts: 37
Default XML parsing problem

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"/>




vzwhaley is offline   Reply With Quote
Old 08-02-2007, 05:23 PM   #2
drkstr's Avatar
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587

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?

drkstr is offline   Reply With Quote
Old 08-02-2007, 05:35 PM   #3
Registered User
Join Date: Jan 2006
Posts: 37

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.
vzwhaley is offline   Reply With Quote
Old 08-03-2007, 01:02 AM   #4
drkstr's Avatar
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587

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,
drkstr is offline   Reply With Quote
Old 08-04-2007, 12:38 PM   #5
Jim Freer
Senior Member
Join Date: Jul 2007
Location: Houston, TX
Posts: 355
Send a message via Yahoo to Jim Freer

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.
Jim Freer is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem loading XML - xml news figo84 ActionScript 2.0 2 10-30-2007 09:54 AM
XML and IF condition problem servalman ActionScript 2.0 8 07-17-2007 02:01 PM
Problem Solvers, Help Me! XML & SimpleViewer brainfreeze ActionScript 2.0 3 04-03-2007 05:21 AM
XML loop problem pasteur ActionScript 2.0 3 02-04-2007 04:12 PM
CSS and XML problem Therian ActionScript 2.0 4 01-31-2007 10:36 PM

All times are GMT. The time now is 07:38 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.