registerNamespace() public method

register a namespace prefix for the document, it will be used in createElement and setAttribute
public registerNamespace ( string $prefix, string $namespace )
$prefix string
$namespace string
Beispiel #1
0
 /**
  * Create and return a JSONx document.
  *
  * @return Document
  */
 public function getDocument()
 {
     $document = new Document();
     $document->registerNamespace('json', self::XMLNS_JSONX);
     $this->addNode($document, $this->_document->documentElement);
     return $document;
 }
 /**
  * @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;
 }
Beispiel #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;
 }
Beispiel #4
0
 /**
  * @see Loadable::loadFragment
  *
  * @param string $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return DocumentFragment|NULL
  */
 public function loadFragment($source, $contentType, $options = [])
 {
     if ($this->supports($contentType) && !empty($source)) {
         $document = new Document();
         $document->preserveWhiteSpace = FALSE;
         $document->registerNamespace('jx', self::XMLNS_JSONX);
         $sourceFragment = $document->createDocumentFragment();
         $sourceFragment->appendXml($source);
         $target = new Document();
         $target->registerNamespace('json', self::XMLNS_JSONDOM);
         $targetFragment = $target->createDocumentFragment();
         foreach ($sourceFragment->childNodes as $node) {
             $this->transferNode($node, $targetFragment);
         }
         return $targetFragment;
     }
     return NULL;
 }
Beispiel #5
0
 /**
  * @param string $prefix
  * @param string $namespaceUri
  */
 public function registerNamespace($prefix, $namespaceUri)
 {
     $this->_document->registerNamespace($prefix, $namespaceUri);
 }