|
|
|
|
|
|
|
|
|
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 ...');
?> | | |
|
| RSS parser using PHP5 and simpleXML Categories : Rich Site Summary (RSS), PHP, XML | | | MySQL to XML. Categories : MySQL, XML, PHP | | | 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 | | | DBXML- A Class to backup databases in XML Format using web interface Categories : PHP, PHP Classes, Databases, MySQL, XML | | | Dynamic Loading of XML array data into ComboBox and Display XML data using PHP + DOM + Javascript. Categories : PHP, Java Script, DOM XML, XML, Arrays | | | SAPIPROCESSOR - is a compact XML-based CMS toolkit Categories : PHP, Content Management, XML | | | XML Menu Categories : PHP, PHP Classes, Navigation, XML, XSL | | | A very basic and fast XML parser Categories : PHP, PHP Classes, XML | | | 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 | | | TAB_STRUCT Class: Is supporting Class for the DBXML Class Categories : PHP, PHP Classes, MySQL, XML, Databases | | | logger class (PHP5 +) Categories : PHP, PHP Classes, Log Files, XML | | | XMLManipulation Categories : PHP, XML, SimpleXML | | | Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +) Categories : PHP, Ecommerce, XML, Web Services, CURL | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Glossword - glossary compiler Categories : Content Management, PHP, MySQL, XML | |
| |
| |
|