FluentDOM\Element::appendElement PHP Method

appendElement() public method

Append an child element
public appendElement ( string $name, string $content = '', array $attributes = NULL ) : Element
$name string
$content string
$attributes array
return Element
    public function appendElement($name, $content = '', array $attributes = NULL)
    {
        $this->appendChild($node = $this->getDocument()->createElement($name, $content, $attributes));
        return $node;
    }

Usage Example

Example #1
0
 /**
  * @param Document|Element $parent
  * @param \DOMElement $node
  * @param bool $addNameAttribute
  */
 public function addNode($parent, \DOMElement $node, $addNameAttribute = FALSE)
 {
     switch ($this->getType($node)) {
         case 'object':
             $result = $parent->appendElement('json:object');
             $this->appendChildNodes($result, $node, TRUE);
             break;
         case 'array':
             $result = $parent->appendElement('json:array');
             $this->appendChildNodes($result, $node, FALSE);
             break;
         case 'number':
             $result = $parent->appendElement('json:number', $node->nodeValue);
             break;
         case 'boolean':
             $result = $parent->appendElement('json:boolean', $node->nodeValue);
             break;
         case 'null':
             $result = $parent->appendElement('json:null');
             break;
         default:
             $result = $parent->appendElement('json:string', $node->nodeValue);
             break;
     }
     if ($addNameAttribute) {
         $name = $node->localName;
         if ($node->hasAttributeNS(self::XMLNS_JSONDOM, 'name')) {
             $name = $node->getAttributeNS(self::XMLNS_JSONDOM, 'name');
         }
         $result['name'] = $name;
     }
 }
All Usage Examples Of FluentDOM\Element::appendElement