PHP Conference Fukuoka 2025

XMLReader::expand

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

XMLReader::expandRetorna uma cópia do nó atual como um objeto DOM

Descrição

public XMLReader::expand(?DOMNode $baseNode = null): DOMNode|false

Este método copia o nó atual e retorna o objeto DOM apropriado.

Parâmetros

baseNode

Um DOMNode que define o DOMDocument de destino para o objeto DOM criado.

Valor Retornado

O DOMNode resultante ou false em caso de erro.

adicionar nota

Notas de Usuários 1 note

up
0
Sbastien
3 years ago
XMLReader::expand() expands the current subtree to DOM. SimpleXML is good too. To avoid a warning like "Imported Node must have associated Document" when using simplexml_import_dom(), we can do :<?php // Huge XML compressed file$xml = XMLReader::open('compress.zlib:///path/to/my-data.xml.gz');// Targeting a tiny subtreewhile ($xml->name !== 'my-targeted-element') {    $xml->read();}// The trick is here...// Subtree is expanded in an empty document...$dom = $xml->expand(new DOMDocument());// ... which can be imported by SimpleXML$sx = simplexml_import_dom($dom);// We can now process our tiny subtree with SimpleXML $sx
To Top