/** * 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; }
/** * @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; }
/** * Load the json string into an DOMDocument * * @param mixed $source * @param string $contentType * @param array|\Traversable|Options $options * @return Document|Result|NULL */ public function load($source, $contentType, $options = []) { if (FALSE !== ($json = $this->getJson($source, $contentType))) { $document = new Document('1.0', 'UTF-8'); $document->appendChild($root = $document->createElementNS(self::XMLNS, 'json:json')); $this->transferTo($root, $json); return $document; } return NULL; }
/** * @see Loadable::load * @param mixed $source * @param string $contentType * @param array|\Traversable|Options $options * @return Document|Result|NULL */ public function load($source, $contentType, $options = []) { $hasHeaderLine = isset($options['HEADER']) ? (bool) $options['HEADER'] : !isset($options['FIELDS']); $this->configure($options); if ($this->supports($contentType) && ($lines = $this->getLines($source))) { $document = new Document('1.0', 'UTF-8'); $document->appendChild($list = $document->createElementNS(self::XMLNS, 'json:json')); $list->setAttributeNS(self::XMLNS, 'json:type', 'array'); $this->appendLines($list, $lines, $hasHeaderLine, isset($options['FIELDS']) ? $options['FIELDS'] : NULL); return $document; } return NULL; }
/** * Load the json string into an DOMDocument * * @param mixed $source * @param string $contentType * @param array|\Traversable|Options $options * @return Document|Result|NULL */ public function load($source, $contentType, $options = []) { if (FALSE !== ($json = $this->getJson($source, $contentType))) { $dom = new Document('1.0', 'UTF-8'); $dom->appendChild($root = $dom->createElementNS(self::XMLNS, 'json:json')); $onMapKey = $this->_onMapKey; if (isset($options[self::ON_MAP_KEY]) && is_callable($options[self::ON_MAP_KEY])) { $this->onMapKey($options[self::ON_MAP_KEY]); } $this->transferTo($root, $json, $this->_recursions); $this->_onMapKey = $onMapKey; return $dom; } return NULL; }
/** * Load the YAML string into an DOMDocument * * @param mixed $source * @param string $contentType * @param array $options * @return Document|NULL */ public function load($source, $contentType, array $options = []) { if ($this->supports($contentType)) { if (FALSE === strpos($source, "\n")) { $source = file_get_contents($source); } $yaml = Dipper::parse($source); if (!empty($yaml) || is_array($yaml)) { $dom = new Document('1.0', 'UTF-8'); $dom->appendChild($root = $dom->createElementNS(self::XMLNS, 'json:json')); $this->transferTo($root, $yaml); return $dom; } } return NULL; }
/** * 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; }