views:

203

answers:

4

Everything seems to be a string right now & that kinda ruins the whole xml as an internal data structure thing, I don't need a big tree of string I need typed data :-/ Are there any changes I can make to either my XML files or my AS3 code that will force it to cast ints as ints and Numbers as Numbers? Or maybe some kind of type schema I can impose?

Not really worked with XML til recently so chances are I'm just ignorant of the canonical way to deal with this... enlightenment please gurus!

Thanks :)

Roger.

+1  A: 

One easy way to accomplish this is import a WSDL from your web service if that's how you are retrieving your XML. Not only will Flex Builder generate the classes for you, but the web service's response will be strongly typed.

skalburgi
Using Flash not Flex and it's not a webservice as such. What I need is for Flash to strongly type data it reads in from a static XML file. I have created an XML schema but I've no idea how to get my flash app to use the damn thing :-(
+2  A: 

XML is a bunch of strings, and as such it isn't well suited for internal storing of data since it wasn't designed for fast and efficient access of information at all. There's nothing that can be done about it.

Instead of storing your internal data in an XML structure, you'll be better off designing a separate class for storing your data, and then just importing and exporting the data to XML. If your input files are complex and/or change frequently, then Flex Builder is probably the best solution, since it has WSDL and XMl schema support built in.

jpop
Hmm, that's what I was afraid of. Building an extra class seemed like it must be a kludge and I assumed I was just missing some bit of syntax but I guess not :-(
A: 

Have you tried using JSON? You can get a deserializer in the as3corelib project on Google Code.

http://code.google.com/p/as3corelib/

Chris Bos
A: 

This fantastic little class does exactly what you want, assuming that you are using VOs for storing the parsed data (more or less the "canonical" approach you asked about).

http://dispatchevent.org/roger/instant-model-binding-with-reflection/

More generally, the same site has a very thorough discussion of AS3 and E4X here:

http://dispatchevent.org/roger/as3-e4x-rundown/

I heartily recommend it.

Coded Signal