inserting information xml record php dom


i perplexing insert new information an existent xml file, nonetheless it's working. here's xml file:



<list>
<activity>swimming</activity>
<activity>running</activity>
<list>


now, thought origination twin files: an index page, where displays what's record provides domain inserting new elements, php page insert information xml file. here's formula index.php:



<html>
<head><title>test</title></head>
</head>

<?php
$xmldoc = new domdocument();
$xmldoc->load('sample.xml', libxml_noblanks);

$activities = = $xmldoc->firstchild->firstchild;
if($activities!=null){
while(activities!=null){
relate $activities->textcontent.'<br/>';
activities = activities->nextsibling.
}
}
?>

<form name='input' action='insert.php' method='post'>
insert activity:
<input type='text' name='activity'/>
<input type='submit' value='send'/>
</form>
</body>
</html


and here's formula insert.php:



<?php
header('location:index.php');
$xmldoc = new domdocument();
$xmldoc->load('sample.xml');

$newact = $_post['activity'];

$root = $xmldoc->firstchild;

$newelement = $xmldoc->createelement('activity');
$root->appendchild($newelement);
$newtext = $xmldoc->createtextnode($newact);
$newelement->appendchild($newtext);

$xmldoc->save('sample.xml');
?>


the user opening index.php, where list tide activities donation xml file, calm domain next where insert new activities. on clicking send button, page insert.php, contains formula opens xml record dom tree, inserts new node underneath bottom node calls behind index.php page, where user should means list activities, new activity there underneath others. working. i click symbol quarrel new entry, pages refreshes apparently zero happens, xml same before. i wrong? also, i'd know there's improved proceed doing it.



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members