Пример #1
0
 /**
  * Create a namespace optimizer for the provided document. The provided
  * document will be copied.
  *
  * The second argument allows to provide namespaces and prefixes. The
  * keys of the array are the namespace uri, the values are the prefixes.
  *
  * If a namespace is not provided it is read from the source node.
  *
  * You can use the same prefix for multiple namespace uris. Empty prefixes
  * are possible (default namespace for an element).
  *
  * It is highly recommend that you always use a non-empty prefix if the
  * here are attributes in that namespace. Attributes always need a prefix
  * to make use of the namespace.
  *
  * @param \DOMDocument $document
  * @param array $namespaces
  */
 public function __construct(\DOMDocument $document, array $namespaces = [])
 {
     $this->_document = new Document();
     foreach ($document->childNodes as $node) {
         $this->_document->appendChild($this->_document->importNode($node, TRUE));
     }
     $this->_namespaceUris = $namespaces;
 }
Пример #2
0
 /**
  * @see Loadable::load
  * @param \SimpleXMLElement $source
  * @param string $contentType
  * @param array|\Traversable|Options $options
  * @return Document|Result|NULL
  */
 public function load($source, $contentType, $options = [])
 {
     if ($source instanceof \SimpleXMLElement) {
         $document = new Document();
         $document->appendChild($document->importNode(dom_import_simplexml($source), TRUE));
         return new Result($document, 'text/xml');
     }
     return NULL;
 }
Пример #3
0
 /**
  * Load a HTML5 file and copy it into a FluentDOM\Document
  *
  * @codeCoverageIgnore
  *
  * @see Loadable::load
  * @param string $source
  * @param string $contentType
  * @param array $options
  * @return Document|NULL
  */
 public function load($source, $contentType, array $options = [])
 {
     if ($this->supports($contentType)) {
         $html5 = new HTML5Support();
         if ($this->startsWith($source, '<')) {
             $dom = $html5->loadHTML($source);
         } else {
             $dom = $html5->loadHTMLFile($source);
         }
         if (!$dom instanceof Document) {
             $fd = new Document();
             if ($dom->documentElement instanceof \DOMElement) {
                 $fd->appendChild($fd->importNode($dom->documentElement, TRUE));
             }
             $dom = $fd;
         }
         $dom->registerNamespace('html', 'http://www.w3.org/1999/xhtml');
         return $dom;
     }
     return NULL;
 }