note 81540 added to function.dom-domxpath-query

From: Date: Mon, 03 Mar 2008 14:14:40 +0000
Subject: note 81540 added to function.dom-domxpath-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-136691@lists.php.net to get a copy of this message
I've searched the entire web looking for a way to update / modify/ change/ alter the elements of an xml file and found NOTHING! So here it is, the defninitive way to "Change XML elements with PHP" rather than adding / appending new ones. This uses XPATH: <?php // Create a DOMDocument instance $xml = new DOMDocument; // Ignore whitespace between nodes (default: true) $xml->preserveWhiteSpace = false; $file='about.xml'; // Load the XML data source $xml->Load($file); $xpath = new DOMXPath($xml); $query='/regions/branch'; $entries = $xpath->query($query); foreach ($entries as $entry) { $entry->firstChild->nodeValue="like this!"; echo $entry->firstChild->nodeValue; } $xml->save($file); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 90.207.121.131 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domxpath-query.php Edit -- https://master.php.net/note/edit/81540 Del: integrated -- https://master.php.net/note/delete/81540/integrated Del: useless -- https://master.php.net/note/delete/81540/useless Del: bad code -- https://master.php.net/note/delete/81540/bad+code Del: spam -- https://master.php.net/note/delete/81540/spam Del: non-english -- https://master.php.net/note/delete/81540/non-english Del: in docs -- https://master.php.net/note/delete/81540/in+docs Del: other reasons-- https://master.php.net/note/delete/81540 Reject -- https://master.php.net/note/reject/81540 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136691) next »