Search
 
SCRIPT & CODE EXAMPLE
 

PHP

remove element from xml on php

<?php

$doc = new DOMDocument; 
$doc->load('theFile.xml');

$thedocument = $doc->documentElement;

//this gives you a list of the messages
$list = $thedocument->getElementsByTagName('message');

//figure out which ones you want -- assign it to a variable (ie: $nodeToRemove )
$nodeToRemove = null;
foreach ($list as $domElement){
  $attrValue = $domElement->getAttribute('time');
  if ($attrValue == 'VALUEYOUCAREABOUT') {
    $nodeToRemove = $domElement; //will only remember last one- but this is just an example :)
  }
}

//Now remove it.
if ($nodeToRemove != null)
$thedocument->removeChild($nodeToRemove);

echo $doc->saveXML(); 
?>
Comment

PREVIOUS NEXT
Code Example
Php :: run a php site 
Php :: php imagick xampp windows 
Php :: phpspreadsheet set cell by column and row 
Php :: filter validate email php 
Php :: php credit card validation 
Php :: laravel collection put 
Php :: invalid datetime format laravel 
Php :: show php all errors 
Php :: laravel create or update eloquesnt 
Php :: larave Soft Deletes 
Php :: laravel where multiple conditions on single colmn 
Php :: Class "AppHttpControllersAdminController" not found in laravel 8 
Php :: wordpress custom php use wp query 
Php :: Merge Two Array ( Laravel ) 
Php :: export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH 
Php :: IlluminateContractsContainerBindingResolutionException target calss does not exist 
Php :: convert an integer to a string in PHP 
Php :: hash password laravel 
Php :: php mysql prepare query 
Php :: str_replace smarty template 
Php :: Laravel adding Foreign Key Constraints 
Php :: date format in wordpress post 
Php :: echo php 
Php :: how to serve the port in php 
Php :: int to char php 
Php :: wordpress post type template 
Php :: laravel 5 use env variable in blade 
Php :: php mail 
Php :: wp_query post id 
Php :: laravel eloquent relationships count 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =