Exemplo n.º 1
0
 /**
  *	Sets content of the specified tag
  *	@method		setTagContent
  *	@param		mixed content
  *	@param		optional string tagPath
  *	@returns	true if successful, false otherwise
  */
 function setTagContent($content, $tagPath = "")
 {
     if ($tagPath == "") {
         $tagPath = $this->tag->getTagName();
     }
     $success = true;
     $tags = explode($this->pathSeparator, $tagPath);
     if ($this->tag->getTagName() == $tags[0]) {
         if (sizeof($tags) == 1) {
             //$this->nodes = array(new XMLLeaf($content));
             $this->removeAllNodes();
             $this->addXMLLeaf(new XMLLeaf($content));
         } else {
             $nodeTagFound = false;
             reset($this->nodes);
             $arrKeys = array_keys($this->nodes);
             for ($index = 0; $index < count($arrKeys); $index++) {
                 $node =& $this->nodes[$arrKeys[$index]];
                 if (strtolower(get_class($node)) == "xmlbranch") {
                     if ($node->tag->getTagName() == $tags[1]) {
                         $newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
                         $success = $node->setTagContent($content, $newTagPath);
                         $nodeTagFound = true;
                     }
                 }
             }
             if (!$nodeTagFound) {
                 $branch = new XMLBranch();
                 $branch->setTag(new Tag($tags[1]));
                 $newTagPath = implode($this->pathSeparator, array_slice($tags, 1));
                 $branch->setTagContent($content, $newTagPath);
                 $this->addXMLBranch($branch);
             }
         }
     }
     return $success;
 }