View Full Version : XML/DB data access question(s)

10-29-2006, 05:59 PM
Ok I'll admit that my head is kind of reeling right now so I'll do my best to explain what I'm trying to do here. Please bear with me. I think one thing that's going on is I'm trying to solve too many problems at one time.

Let me try to explain. I seemed to be having some coldfusion problems so I'm unable to access some data for a customer. So then I obtained the database, or a sample of it, in Access Format (as an Access DB). Then when I got that, I thought for a bit and said to myself "Self, how the <bleep> are you going to get the data from an Access DB into the Flex progam?" Good point. So then I took that data and exported it into an XML file. Organized it nicely (cuz MSAccess sucks exporting to XML at least for my purposes.) So now I'm sitting here with an XML file

Now before I get to the more immediate problem let me say something that has been bugging me. Shouldn't there be a more generic concept in use here? Am I totally missing something here? I guess the best way to explain it is thru a kind of ADO concept. Something to relatively generically access data from different data sources. Just a question/idea to throw out to everyone.

As far as the immediate problem, here's the deal.

I've got an XML File in the following format:

<month name="Apr-06">
<company ID="01">
<record conf#="1111" (other attributes as well) />
<record conf#="22222" (other attributes as well) />
<record conf#="62598" (other attributes as well) />
<company ID="757">
<record conf#="333" (other attributes as well) />
<record conf#="89452" (other attributes as well) />
<record conf#="45678" (other attributes as well) />
<month name="May-06">
<company ID="01">
<record conf#="1111" (other attributes as well) />
<record conf#="33333" (other attributes as well) />
<record conf#="48972" (other attributes as well) />
(other months...)</list>

Now I've got a dialog (popup/titlewindow) that's going to come up. It will be passed in the month that is desired and the company ID. The dialog is relatively simple, just containing a datagrid. The datagrid will hold information as far as the attribute for each record (theoretically record=row attribute=column).

So what I'm seeing is that first a "search" of the XML needs to be done. To put it SQL-ishly something like Select * from list where companyID="01" and month="Apr-06"

The question is, in my mind, how to do this and what's the best way to do this so that it is relatively independent of the means of data access.

I'm sorry if I'm being a bit unclear here. If I need to clarify things further please let me know. Any help would be much appreciated.


11-02-2006, 06:53 PM
I'm by no means an XML expert when it comes to Flex, but it looks like they have the necessary classes to read and parse an XML file:


From there, at the very least, you could set up a loop to run through your XML and grab whatever you needed. It unfortunately doesn't look like it has any XPath support though, which would have eliminated the need for looping over the child elements. :(

11-02-2006, 07:05 PM
Yeah thanks medd..I got it figured out as far as the XML ...LOL finally...and they do have some ...well not Xpath but they have operators to be used...

here's a brief overview (skimpy I'll admit) of what I did
1) Load the XML using URLLoader (see documentation)
2) In result handler get the XML put in something like the following:
private function completeHandler(event:Event):void
var example:XML = new XML(event.target.data);
var ourList:XMLList = example.month.(@name == monthString).company.(@ID == compIDString).children();

ourData = new XMLListCollection(ourList);
catch (e:TypeError)
Alert.show("There was a problem in the completeHandler");
ourData was an XMLListCollection and then I put that in as the dataProvider for the DataGrid.

I think was really getting to me was the fact that I couldn't write "one set of code" for either an XML file as my source, or Access DB as my source or mySQL as my source, etc. Kinda ADO-ish I guess. But LOL I got over that in a hurry and got on to "getting the job done" now I'm working on other problems. You know how it is LOL

Thanks again, and take care (and I'll take a look at your post and see if I have any ideas),

11-02-2006, 09:21 PM
Oh yeah, I know how that goes :D

For getting an ADO-like interface, ColdFusion has Datasources you can set up to handle different ... sources of data (Trying to think up another name for Datasources :P)... no matter where your data is (whether it's Access, MySQL, or MSSQL) you could use the same code.

Far as Flex having that functionality... I doubt that it does. Flex is supposed to be the "View" component of the Model/View/Controller design. It's not set up to directly interact with your Model (data) -- it should make requests to the Model through your Controller.

And hey, thanks for the reply to my debug thread... you have no idea how many headaches that's going to save me :D

11-03-2006, 07:19 AM
Yeah I think in a way I've been letting my "learning process" get in the way of my "getting the job done" process. I mean I pretty much jumped into this whole flex/flash/ria thing less than 2 weeks ago and I'm not saying to myself "Self, regardless of the language and technologies and such, what's the best organizational structures needed." And things like that. I've been reading a great book (And looking at tons of code and blogs et. al. on the web), the book is entitled "developing rich clients with macromedia flex" (http://www.amazon.com/Developing-Rich-Clients-Macromedia-Flex/dp/0321255666/sr=8-3/qid=1162541122/ref=sr_1_3/102-7648747-1720962?ie=UTF8&s=books) it's by Steven Webster (http://weblogs.macromedia.com/swebster/) and Alistair McCleod. They're the guys who did a lot of work on Cairngorm. I'd really recommend the book, even though it's dated 2004 and is for 1.5 a lot of the concepts still hold true today. I just wish I could figure out what happened to their website(s) (richinternetapps.com and iterationtwo.com) they seemed to be mentioned all over the place but every time I go to them they seem to be down.

Anyway was reading tonight (or this morning whichever you'd consider it, it was 2 am) about Value Objects and that's pretty much the way I'd been thinking. A set of data classes with strongly typed data members. So it looks like I'm slowly but surely adopting at least some concepts of Cairngorm LOL.

And I noticed the article I referenced in my post on the other thread worked for you. I'm glad to hear it.