note 126739 added to xmlreader.expand
| From: | Sbastien at main dot php dot net | Date: | Sun, 02 Jan 2022 13:29:04 +0000 |
| Subject: | note 126739 added to xmlreader.expand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217455@lists.php.net to get a copy of this message | ||
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 subtree
while ($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
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 2a01:e0a:968:1840:d166:44e4:8afa:c08)
----
Manual Page -- https://php.net/manual/en/xmlreader.expand.php
Edit -- https://main.php.net/note/edit/126739
Del: integrated -- https://main.php.net/note/delete/126739/integrated
Del: useless -- https://main.php.net/note/delete/126739/useless
Del: bad code -- https://main.php.net/note/delete/126739/bad+code
Del: spam -- https://main.php.net/note/delete/126739/spam
Del: non-english -- https://main.php.net/note/delete/126739/non-english
Del: in docs -- https://main.php.net/note/delete/126739/in+docs
Del: other reasons-- https://main.php.net/note/delete/126739
Reject -- https://main.php.net/note/reject/126739
Search -- https://main.php.net/manage/user-notes.php