|
|
|
|
|
|
|
|
|
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 | |
| |
| |
|