appendElement() public method

Overload appendElement to add a text content and attributes directly.
public appendElement ( string $name, string $content = '', array $attributes = NULL ) : Element
$name string
$content string
$attributes array
return Element
 /**
  * @see Loadable::load
  * @param mixed $source
  * @param string $contentType
  * @param array $options
  * @return Document|NULL
  */
 public function load($source, $contentType, array $options = [])
 {
     if ($this->supports($contentType) && ($this->_lines = $this->getLines($source))) {
         $dom = new Document('1.0', 'UTF-8');
         $dom->registerNamespace('', $this->_namespace);
         $dom->appendElement($this->_nodeNames['root'])->append($this);
         return $dom;
     }
     return NULL;
 }
Example #2
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;
     }
 }
Example #3
0
 /**
  * @see Loadable::load
  * @param \PDOStatement $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return Document|Result|NULL
  */
 public function load($source, $contentType, $options = [])
 {
     if ($source instanceof \PDOStatement) {
         $document = new Document('1.0', 'UTF-8');
         $document->registerNamespace('json', self::XMLNS);
         $root = $document->appendElement('json:json');
         $source->setFetchMode(\PDO::FETCH_OBJ);
         foreach ($source as $row) {
             $child = $root->appendElement('_');
             $this->transferTo($child, $row, 1);
         }
         return new Result($document, 'text/xml');
     }
     return NULL;
 }