PDA

View Full Version : Add to XML data?


matbury
10-21-2007, 07:55 PM
I'm a newbie to AS 3.0 and I've been looking at how it handles XML.

Wow! They've saved me a lot of work.

I'm getting the hand of reading in XML and the various ways of extracting data from it.

What I'm wondering is, can AS 3.0 add data to an XML file? If so is it as simple as reading it?

Does the XML class handle the nodes and attributes and stuff for you, you know, like adding a new node that contains nested nodes?

What I'd like to do is have Flash create XML for export to PHP to write XML files on the fly. How easy would that be?

The books I'd like to get on the subject haven't been published here yet, so I'm stuck with Flash Help and Adobe's on-line resources. I'm making my way through them... slowly.

Thanks in advance.

Sekhar
10-21-2007, 10:04 PM
XML is a dynamic class, so you could just add stuff on the fly. E.g.,

var xml:XML = <xml><foo>This is easy</foo></xml>;
trace(xml);
xml.bar = "Yes sirry, Bob!";
trace(xml);

will output:

<xml>
<foo>This is easy</foo>
</xml>
<xml>
<foo>This is easy</foo>
<bar>Yes sirry, Bob!</bar>
</xml>

matbury
10-21-2007, 11:00 PM
Fantastic! That's great news! So you could easily create XML files on the fly with LoadVars and PHP. Is that right?

I'm thinking about making an on-line video subtitling API for educational purposes. The standard is 'Timed Text' XML. It's pretty simple.

LauriL
10-22-2007, 01:44 PM
I'm afraid it's not that simple. The example that Sekhar showed has nothing to do with files. I think you need to use sockets in order to write to xml files. I, myself, am looking info on that subject currently.

matbury
10-22-2007, 02:57 PM
Couldn't you just get PHP to overwrite to the XML file (permissions set to 777) using LoadVars? I've done it with text files before and it worked fine.

FrodoBaggins
10-22-2007, 03:02 PM
that'll do the trick
not really save though ;)