WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Functions to add / remove nodes to / from an XML file using PHP.
Categories : PHP, XML Click here to Update Your Picture
pradnyesh kadam
Date : Mar 02nd 2010
Grade : 3 of 5 (graded 2 times)
Viewed : 3180
File : No file for this code example.
Images : No Images for this code example.
Search : More code by pradnyesh kadam
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples 
Like this code?
Show the author your appreciation.
 

<?php
function removNode($myXML, $node, $attribute, $id) {
   
$xmlDoc = new DOMDocument();
   
$xmlDoc->load($myXML);
   
$xpath = new DOMXpath($xmlDoc);
   
    if(
$attribute!='' || $id!='' )
   
$nodeList = $xpath->query('//'.$node.'[@'.$attribute.'="'.$id.'"]');
    else
   
$nodeList = $xpath->query('//'.$node.'');
   
    if (
$nodeList->length)
    {
       
$node = $nodeList->item(0)  ;
       
$node->parentNode->removeChild($node);
    }
   
$xmlDoc->save($myXML) ;
}   
?>




Example Usage
<?php
removNode
('content.xml','slideshow/slide','id', '10');
?>




Function to add NODES into XML FILE using PHP
<?php   
function addNode($myXML, $parentnode, $childnode, $attribute1, $value1, $attribute2, $value2, $attribute3, $value3 , $attribute4, $value4 , $attribute5, $value5, $text){
   
$doc = new DOMDocument();               
   
$doc->load($myXML);
   
   
$node = $doc->getElementsByTagName($parentnode)->item(0) ; // Node     
   
$slide = $node->appendChild(new DOMElement($childnode)) ;
   
    if(
$text != '')   
   
$slide->appendChild($doc->createTextNode($text));
   
    if(
$attribute1 != '')           
   
$slide->setAttributeNode(new DOMAttr( $attribute1, $value1 ));
   
    if(
$attribute2 != '')   
   
$slide->setAttributeNode(new DOMAttr( $attribute2, $value2 )) ;
   
    if(
$attribute3 != '')
   
$slide->setAttributeNode(new DOMAttr( $attribute3, $value3 )) ;   
   
    if(
$attribute4 != '')
   
$slide->setAttributeNode(new DOMAttr( $attribute4, $value4 )) ;   
   
    if(
$attribute5 != '')
   
$slide->setAttributeNode(new DOMAttr( $attribute5, $value5 )) ;   
       
   
$doc->save($myXML);       
}
?>


Example Usage
<?php
addNode
('content.xml', 'interactive', 'slide', 'id', '2', 'imgid', '5', 'order', '10', '', '', '', '', 'Text Here ...');   
?>



TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
Glossword - glossary compiler
Categories : Content Management, PHP, MySQL, XML
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
php Free chat simple fast and customizable chat server that uses a simple filesystem for message and nickname storage
Categories : PHP, AJAX, XML, Complete Programs
utf8_decode -- Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1.
Categories : PHP, PHP Functions, XML
XML easy parser
Categories : PHP, XML, PHP Classes
Simple newsreader script
Categories : PHP, XML, Rich Site Summary (RSS)
Trivia Quiz program using XML, XSLT and PHP
Categories : PHP, XML, XSLT
Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +)
Categories : PHP, Ecommerce, XML, Web Services, CURL
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
XMLManipulation
Categories : PHP, XML, SimpleXML
On-the-fly drop down menu from a txt or xml file
Categories : PHP, XML, HTML and PHP
MySQL or SQL Query to XML Output
Categories : PHP, MySQL, XML, Databases
RSS parser using PHP5 and simpleXML
Categories : Rich Site Summary (RSS), PHP, XML