FluentDOM\Document::registerNamespace PHP Method

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
    public function registerNamespace($prefix, $namespace)
    {
        $prefix = $this->validatePrefix($prefix);
        if (isset($this->_reserved[$prefix])) {
            throw new \LogicException(sprintf('Can not register reserved namespace prefix "%s".', $prefix));
        }
        $this->_namespaces[$prefix] = $namespace;
        if (isset($this->_xpath) && $prefix !== '#default') {
            $this->_xpath->registerNamespace($prefix, $namespace);
        }
    }

Usage Example

Example #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;
 }
All Usage Examples Of FluentDOM\Document::registerNamespace