sorry, no I will not be using a database. basically I want a form that will submit values to a php page and add them to a xml file.. but updating it. here is what I got so far.
<?
$file = "myshout.xml";
$xml_headline_key = "*SHOUTSET*SHOUT*NAME";
$xml_description_key = "*SHOUTSET*SHOUT*MSG";
$xml_color_key = "*SHOUTSET*SHOUT*COLOR";
$story_array = array();
$counter = 0;
class xml_story{
var $headline, $description, $color;
}
function startTag($parser, $data){
global $current_tag;
$current_tag .= "*$data";
}
function endTag($parser, $data){
global $current_tag;
$tag_key = strrpos($current_tag, '*');
$current_tag = substr($current_tag, 0, $tag_key);
}
function contents($parser, $data){
global $current_tag, $xml_headline_key, $xml_description_key, $xml_color_key, $counter, $story_array;
switch($current_tag){
case $xml_headline_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->headline = $data;
break;
case $xml_description_key:
$story_array[$counter]->description = $data;
$counter++;
break;
case $xml_color_key:
$story_array[$counter]->color = $data;
$counter++;
break;
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
$myFile = "testFile.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = '<?xml version="1.0" encoding="UTF-8"?>'.chr(13);
$stringData .= '<shoutset>'.chr(13);
// Old Data
for($x=0;$x<count($story_array);$x++){
$stringData .= '<shout>'.chr(13);
$stringData .= '<name>'.$story_array[$x]->headline.'</name>'.chr(13);
$stringData .= '<color>'.$story_array[$x]->color.'</color>'.chr(13);
$stringData .= '<msg>'.$story_array[$x]->description.'</msg>'.chr(13);
$stringData .= '</shout>'.chr(13).chr(13);
}
$stringData .= '<shout>'.chr(13);
//New Data
$stringData .= '<test1>test1</test1>'.chr(13);
$stringData .= '<test2>test2</test2>'.chr(13);
$stringData .= '<test3>test3</test3>'.chr(13);
$stringData .= '</shout>'.chr(13);
$stringData .= '</shoutset>'.chr(13);
fwrite($fh, $stringData);
//$stringData = "<shoutset>\n";
//fwrite($fh, $stringData);
fclose($fh);
?>
but then my xml file comes out like this
<?xml version="1.0" encoding="UTF-8"?>
<shoutset>
<shout>
<name>Jon Doe</name>
<color>#FF0000</color>
<msg></msg>
</shout>
<shout>
<name></name>
<color></color>
<msg>Hey!</msg>
</shout>
<shout>
<name>Dooger</name>
<color>#33FF00</color>
<msg></msg>
</shout>
<shout>
<name></name>
<color></color>
<msg>Hey nice profile!</msg>
</shout>
<shout>
<name>Natzi</name>
<color>#FFFDC2</color>
<msg></msg>
</shout>
<shout>
<name></name>
<color></color>
<msg>I'll Cutt u</msg>
</shout>
<shout>
<name>Dooger</name>
<color>#33FF00</color>
<msg></msg>
</shout>
<shout>
<name></name>
<color></color>
<msg>Thanks for the add</msg>
</shout>
<shout>
<test1>test1</test1>
<test2>test2</test2>
<test3>test3</test3>
</shout>
</shoutset>
notice the blank data in the xml file?