Пример #1
0
 private function parseNode(XmlElement $node)
 {
     $className = ucfirst($node->getName());
     if (!ClassCache::exists($className)) {
         $instance = new HtmlComponent($node->getName(), $node->getText(), $node->getAttributes());
     } else {
         if (!ClassUtil::isSubclassOf($className, "Component")) {
             throw new ComponentNotExistsException($className);
         }
         $instance = new $className();
         foreach ($node->getAttributes() as $attrName => $attrValue) {
             $setterName = "set" . ucfirst($attrName);
             $setter = new ReflectionMethod($instance, $setterName);
             $setter->invoke($instance, (string) $attrValue);
         }
     }
     foreach ($node->getChildren() as $child) {
         $instance->addChild($this->parseNode($child));
     }
     return $instance;
 }
Пример #2
0
 /**
  * @param XmlElement $toAppend
  * @param boolean $root
  * @return void
  */
 public function appendChild($toAppend, $root = false)
 {
     if ($root) {
         $node = $this->addChild($toAppend->getName());
         foreach ($toAppend->attributes() as $key => $value) {
             $node->addAttribute($key, $value);
         }
         $node->appendChild($toAppend);
     } else {
         foreach ($toAppend as $name => $tree) {
             $child = $this->addChild($name, $this->_fixContent(strval($tree)));
             foreach ($tree->attributes() as $attrKey => $attrValue) {
                 $child->addAttribute($attrKey, $attrValue);
             }
             $child->appendChild($tree->children());
         }
     }
 }
Пример #3
0
 /**
  * Append other XMLElement, support namespaces.
  *
  * @param XmlElement $append
  */
 public function append($append)
 {
     //if ( $append ) not working for 'defs'
     if (isset($append)) {
         //list all namespaces used in append object
         $namespaces = $append->getNameSpaces();
         //get all childs
         if (strlen(trim((string) $append)) == 0) {
             $xml = $this->addChild($append->getName());
             foreach ($append->children() as $child) {
                 $xml->append($child);
             }
         } else {
             //add one child
             $xml = $this->addChild($append->getName(), (string) $append);
         }
         //add simple attributes
         foreach ($append->attributes() as $attribute => $value) {
             $xml->addAttribute($attribute, $value);
         }
         //add attributes with namespace example xlink:href
         foreach ($namespaces as $index => $namespace) {
             foreach ($append->attributes($namespace) as $attribute => $value) {
                 $xml->addAttribute($index . ':' . $attribute, $value, $namespace);
             }
         }
     }
 }