PDA

View Full Version : save xml object into xml file


snail28
09-24-2008, 09:09 AM
// create an XML document
var doc:XML = new XML();

// create three XML nodes using createElement()
var element1:XMLNode = doc.createElement("level");

// place the new nodes into the XML tree
doc.appendChild(element1);
element1.appendChild(element2);


listenerKey.onKeyDown = function(){

//save data into variable
Rec.keycode = Key.getCode().toString();
Rec.beatTime = (getTimer() / 100).toString();
dataRec.push(Rec);

var keycode_node:XMLNode = doc.createElement("keyCode");
keycode_node.appendChild( doc.createTextNode( Rec.keycode ) );

var beatTime_node:XMLNode = doc.createElement("beatTime");
beatTime_node.appendChild( doc.createTextNode( Rec.beatTime ) );

//place data into xml tree
element1.appendChild(keycode_node)
element1.appendChild(beatTime_node)
trace (doc);

}


I wrote this code for insert data into xml object, and the result in the output :

for example i pressed 2 different key at different time (check out my code)

<level>
<keyCode>65</keyCode>
<beatTime>13.94</beatTime>
<keyCode>83</keyCode>
<beatTime>17.39</beatTime>
</level>

I understand that it needs Php and honestly i just can't understand what function do i have to use.and my problem is, i want to save the xml object into xml file. does anyone here has a sample code for my case ? or you can tell me how to do it ?

thanks

CobaltBlueDW
09-24-2008, 10:09 AM
using this function would be one way to do it:
http://us3.php.net/manual/en/function.fwrite.php

snail28
09-24-2008, 05:12 PM
im already use the function and im done write the code in php but, i have a new problem here, the php seems not calling the xml object

here was the php,
<?php

$string = $_GET['doc'];
// declare a variable and assign the text sent to this script

$file = fopen('stage1.xml', 'a');
// for the meaning of the second parameter check http://tr2.php.net/fopen
// but this basically opens the file if it exists or creates it. use double
// period for upper directories like "../somefile.txt'

$write = fwrite($file, $string);
// this variable returns false if this file can not be edited.
// parameter1 is the reference of the file, parameter2 is the string to write

if ($write) {
echo "&result=success&";
// use ambersand sign before the variable name and after the value for flash
// and note that whatever the type of value it will be a string in flash
} else {
echo "&result=failure&";
}
fclose($file);

echo "Doc = " . $string;
echo $string;
?>


did you know where i made a mistake so that when i test the movie the browser show &result=failure which means writing proccess failed ?