note 103155 added to class.domdocumentfragment

From: Date: Tue, 29 Mar 2011 14:00:51 +0000
Subject: note 103155 added to class.domdocumentfragment
Groups: php.notes 
Request: Send a blank email to php-notes+get-178295@lists.php.net to get a copy of this message
DOMDocumentFragment only appears useful if created from a parent DOMDocument eg. 1. $dom = new DOMDocument("1.0","UTF-8"); 2. $docFrag = $dom->createDocumentFragment(); 3. Now append items to $docFrag 4. Graft $docFrag contents back onto $dom at the desired location Conversely taking this approach: 1. $dom = new DOMDocument("1.0","UTF-8"); 2. $docFrag = new DOMDocumentFragment(); 3. Now append items to $docFrag ...will fail on step 3 with a "read only" error as $docFrag is not created as a child of DOMDocument. I'm not sure of the reason for this: on the web people have cited security, and others have cited poor design however whatever the reason, it is really limiting when wanting to encapsulating generic independent DocumentFragments into classes for easy grafting to the desired tree. The only workarounds i have seen look expensive from a performance perspective and cumbersome from a coding perspective ie. create a dummy $dom for temporary use. (This is valid as of PHP 5.3) I've put this here as i've wasted a lot of time finding it out - I hope this saves others some heartache. Using new DOMDocumentFramt ---- Server IP: 69.147.83.197 Probable Submitter: 41.133.237.78 ---- Manual Page -- http://www.php.net/manual/en/class.domdocumentfragment.php Edit -- https://master.php.net/note/edit/103155 Del: integrated -- https://master.php.net/note/delete/103155/integrated Del: useless -- https://master.php.net/note/delete/103155/useless Del: bad code -- https://master.php.net/note/delete/103155/bad+code Del: spam -- https://master.php.net/note/delete/103155/spam Del: non-english -- https://master.php.net/note/delete/103155/non-english Del: in docs -- https://master.php.net/note/delete/103155/in+docs Del: other reasons-- https://master.php.net/note/delete/103155 Reject -- https://master.php.net/note/reject/103155 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178295) next »