The Way to Programming
The Way to Programming
Update/Delete info in XML document via PHP
This is what I got so far
my .xml document
Skuilnaam 8 Skuilnaam1 10 cobus 5
and here i got my file which i want to run to delete my database entries and cleaning the xml entries but im have problem with my xml deletion part
$db_host = "xxxxxxxxxxx";
$db_user = "xxxxxxxxxxxx";
$db_pass = "xxxxxxxxxxxxxx";
$db_name = "xxxxxxxxxxx";
$connect = @mysql_connect($db_host,$db_user,$db_pass);
@mysql_select_db($db_name);
static $leaderboardfile = 'res/leaders.xml';
// Empty table
$query = "TRUNCATE TABLE rente";
mysql_query($query);
?>
load( 'res/leaders.xml' );
$masterElement = $retriever->documentElement;
$masterContent = $masterElement->getElementsByTagName('users')->item(3);
$oldContent = $masterElement->removeChild($masterContent );
echo $retriever->saveXML();
?>
I get the following error message:
Catchable fatal error: Argument 1 passed to DOMNode::removeChild() must be an instance of DOMNode, null given in /srv/disk1/1296487/www/rekvasvra.uni.me/Gr10/Rente/cron.php on line 23
can someone help me find a solution and edit the code for me please im a beginner and is strggling to solve the problem as far as I can see the problem must be
$masterContent = $masterElement->getElementsByTagName('users')->item(3);
If we take a look at this line:
$masterContent = $masterElement->getElementsByTagName('users')->item(3);
You’re trying to fetch the third item of a list, a list which we just determined was empty. Thus it returns null, and it results in you trying to pass null to a method which expects an object.
How to solve it involves some basic logic, which I am sure you can figure out on your own if you just think about it. There are many ways to test for what you want, after all.
I found the solution but there’s something else that is bugging me now
load( 'res/leaders.xml' );
$masterElement = $retriever->documentElement;
$masterContent = $masterElement->getElementsByTagName('user')->item(0);
$oldContent = $masterElement->removeChild($masterContent );
echo $retriever->saveXML();
echo $retriever->save( 'res/leaders.xml' );
?>
This delete each record as I refresh it each time, isn’t there a way to delete all at once or create a table where I can tick off to delete each record? and after I deleted all the records isn’t there a way to tell me there are no more records and link me back to the index? in place of getting the error
Sign in to your account