Source for file SimpleXMLExtended.php

Documentation is available at SimpleXMLExtended.php

  1. <?php
  2.  
  3. /**
  4. @package inc
  5. @subpackage utility
  6. */
  7.  
  8. /**
  9.  *
  10.  * SimpleXMLExtended class for use with CDATA-tags
  11.  *
  12.  * @author Felix Rupp <kontakt@felixrupp.com>
  13.  * @version $Id$
  14.  * @copyright Copyright (c) 2011, Felix Rupp, Nicole Reinhardt
  15.  * @license http://www.opensource.org/licenses/mit-license.php MIT-License
  16.  * @license http://www.gnu.org/licenses/gpl.html GNU GPL
  17.  *
  18.  * @package inc
  19.  * @subpackage utility
  20.  */
  21. class SimpleXMLExtended extends SimpleXMLElement {
  22.     
  23.     
  24.     /**
  25.      * Method to append proper CDATA to a node
  26.      * 
  27.      * @param string $cdata_text 
  28.      * 
  29.      * @return void 
  30.      */
  31.     public function addCData($cdata_text){
  32.         
  33.         $node dom_import_simplexml($this);
  34.         $no $node->ownerDocument;
  35.         $node->appendChild($no->createCDATASection($cdata_text));
  36.         
  37.     // End of method declaration
  38.     
  39.     
  40.     
  41.     /**
  42.      * Create a child with CDATA value
  43.      * 
  44.      * @param string $name The name of the child element to add.
  45.      * @param string $cdataText The CDATA value of the child element.
  46.      * 
  47.      * @return Child element that has been added as SimpleXMLExtended object
  48.      */
  49.     public function addChildCData($name$cdataText=""{
  50.         
  51.         $child $this->addChild($name);
  52.                 
  53.         if(strlen($cdataText)>0{
  54.             
  55.             $child->addCData($cdataText);
  56.             
  57.         }
  58.         
  59.         return $child;
  60.         
  61.     // End of method declaration
  62.     
  63.     
  64.     
  65.     /**
  66.      * Method to remove a node
  67.      * 
  68.      * @return void 
  69.      */
  70.     public function removeNode({
  71.         
  72.         $node dom_import_simplexml($this);
  73.         $node->parentNode->removeChild($node);
  74.         
  75.     // End of method declaration
  76.     
  77.     
  78.     
  79.     /**
  80.      * Method to move a node above one other
  81.      * 
  82.      */
  83.     public function moveNodeUp($refNode{
  84.         
  85.         $oldNode dom_import_simplexml($this);
  86.         $refNode dom_import_simplexml($refNode);
  87.     
  88.         $node $refNode->parentNode->removeChild($oldNode);
  89.         
  90.         $refNode->parentNode->insertBefore($node$refNode);
  91.         
  92.     // End of method declaration
  93.     
  94.     
  95.     
  96.     /**
  97.      * Method to move a node after one other
  98.      *
  99.      */
  100.     public function moveNodeDown($refNode{
  101.             
  102.         $oldNode dom_import_simplexml($this);
  103.         $refNode dom_import_simplexml($refNode);
  104.         
  105.         $node $refNode->parentNode->removeChild($oldNode);
  106.             
  107.         $refNode->parentNode->insertBefore($node$refNode->nextSibling);
  108.     
  109.     // End of method declaration
  110.     
  111. }
  112. ?>