Page 1 of 1

DOM XML problem in updating records

Posted: Thu Feb 03, 2005 9:27 am
by dimitris
The following code inserts a record in the file lessons.xml

Code: Select all

$mode=$_REQUESTї'mode'];
if($mode=='insert'){
	if(isset($_POSTї'submit'])){
		if((strlen($_POSTї'title'])>0) AND (strlen($_POSTї'creator'])>0)){ 
										
						$today = date("d-m-Y G:i:s");
						
						$creator=$_REQUESTї'creator'];
						$title=$_REQUESTї'title'];
						$audience=$_REQUESTї'audience'];
						$description=$_REQUESTї'description'];
						$contents=$_REQUESTї'contents'];
						$contents=ereg_replace("\r\n","їnl]", $contents);
						$respsite=$_REQUESTї'respsite'];
						$url=$_REQUESTї'url'];
						$location=$_REQUESTї'location'];
						$created=$today;
						$modified=$today;
						$keywords=$_REQUESTї'keywords'];
						
						
					
					//$document=domxml_xmltree($f);
					if (!$doc = domxml_open_file("lessons.xml")) {
						echo "The file was found empty.<br>Creating new tree!";
						 
						$doc = domxml_new_doc('1.0');
						$root = $doc->create_element('root'); 
						$root = $doc->append_child($root);
						//Use only if lessons.xml is empty
						&#125;
						
						$root = $doc->document_element();
						
						
						
	
	
	$occ = $doc->create_element('Library');
	$occ = $root->append_child($occ);
	
	$child = $doc->create_element('Creator'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($creator); //fieldvalue
	$value = $child->append_child($value);
	
	$child = $doc->create_element('Title'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($title); //fieldvalue
	$value = $child->append_child($value);
	
	$child = $doc->create_element('Description'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($description); //fieldvalue
	$value = $child->append_child($value);
	
	$child = $doc->create_element('Description.audience'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($audience); //fieldvalue
	$value = $child->append_child($value);
	
	$child = $doc->create_element('Description.contents'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($contents); //fieldvalue
	$value = $child->append_child($value);
	
	while(isset($keywords&#1111;$i]))&#123;
						//echo $keywords&#1111;$i];
	$child = $doc->create_element('Description.keywords'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($keywords&#1111;$i++]); //fieldvalue
	$value = $child->append_child($value);
	&#125;
	
	$child = $doc->create_element('Description.respsite'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($respsite); //fieldvalue
	$value = $child->append_child($value);
	
	$child = $doc->create_element('Description.url'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($url); //fieldvalue
	$value = $child->append_child($value);
	
	$child = $doc->create_element('Date.Created'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($created); //fieldvalue
	$value = $child->append_child($value);
	
	$child = $doc->create_element('Date.Modified'); //fieldname
	$child = $occ->append_child($child);	
	$value = $doc->create_text_node($modified); //fieldvalue
	$value = $child->append_child($value);
	
	
	// get completed xml document 
	$xml_string = $doc->dump_mem(true); 
	
	$f=fopen("lessons.xml","a+");
	fwrite($f,$xml_string);	
	fclose($f);		
&#125;
&#125;
&#125;
&#125;
As i am new in DOM and XML :) ...but i have a bit experience in MySQL
and i can not find the logic how can i increase the primary id count (or whatever) in order to select each record separately?
I believe then it is quite easy to make modifications to existing records...

Thanks for your help in advance!

Posted: Thu Feb 03, 2005 10:09 am
by timvw

Posted: Thu Feb 03, 2005 2:08 pm
by dimitris
timvw wrote:probably you want to use

http://be.php.net/manual/en/function.do ... agname.php
Thanks! I found it very interesting but i would like to know if there is a way to increase an primary key id like mysql records. Some people told me that DOM does it autmaticaly!Does this happen?