PHP 8.1.15 Released!


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

XMLReader::expandDevuelve una copia del actual nodo como un objeto DOM


public XMLReader::expand(DOMNode $basenode = ?): DOMNode

Éste metodo copia el nodo actual y devuelve el apropiado objeto DOM.

Valores devueltos

El resultante DOMNode o false en caso de error.

add a note

User Contributed Notes 1 note

1 year 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 :


// Huge XML compressed file
$xml = XMLReader::open('compress.zlib:///path/to/my-data.xml.gz');

// Targeting a tiny subtree
while ($xml->name !== 'my-targeted-element') {

// 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