Req #43260 [Fbk->NoF]: DOM doesn't produce valid XHTML.
| From: | php-bugs at lists dot php dot net | Date: | Sun, 21 Mar 2021 04:22:08 +0000 |
| Subject: | Req #43260 [Fbk->NoF]: DOM doesn't produce valid XHTML. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232902@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=43260&edit=1
ID: 43260
Updated by: php-bugs@lists.php.net
Reported by: dhopkins at mutinydesign dot co dot uk
Summary: DOM doesn't produce valid XHTML.
-Status: Feedback
+Status: No Feedback
Type: Feature/Change Request
Package: DOM XML related
Operating System: Ubuntu Server
PHP Version: 5.2CVS-2007-11-12 (snap)
Assigned To: cmb
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2021-03-12 12:50:28] cmb@php.net
This feature request appears to be obsolete, isn't it?
------------------------------------------------------------------------
[2013-10-10 07:47:31] datibbaw@php.net
If you want to skip the XML declaration, just pass an argument to
->saveXML, i.e.
echo $doc->saveXML($doc->firstChild);
------------------------------------------------------------------------
[2007-11-18 17:35:57] missingno at ifrance dot com
Yet another possible workaround (also untested):
When you're done preparing your markup:
- use DOMDocument->saveXML() to dump the tree to a string,
- create another DOMDocument, use loadXML() with LIBXML_NOXMLDECL on that string
- finally, dump this new DOMDocument's tree to a file/string using the usual save/saveXML
methods.
------------------------------------------------------------------------
[2007-11-18 17:31:40] missingno at ifrance dot com
In fact, there's already a constant (both in PHP & libxml >= 2.6.21) to drop the XML
declaration, but it seems it can't be used in any of the save*() methods of the DOM extension.
Definition of the PHP constant (LIBXML_NOXMLDECL):
http://cvs.php.net/viewvc.cgi/php-src/ext/libxml/libxml.c?annotate=1.65#l630
Implementation of DOM's SaveXML (dom_document_savexml)
http://cvs.php.net/viewvc.cgi/php-src/ext/dom/document.c?annotate=1.88#l1681
The LIBXML_NOXMLDECL can be used when loading XML data from a file or a string (see DOM
Document's load()/loadXML()).
Maybe this constant should also be available in the options passed to save()/saveXML().
However, you might be able to achieve the same effect by:
- loading your HTML content in a DOMDocument,
- loading a dummy XML file/string (such as "<html />", passing LIBXML_NOXMLDECL as
an option to the load method) in a second DOMDocument (we will refer to it as "the XML
DOMDocument")
- using importNode($node, TRUE) to deep-copy & import the HTML content in the XML DOMDocument
- use save()/saveXML() on the XML DOMDocument to dump the resulting tree
I didn't test this workaround (yet), though.
Also, please note that serving XML as HTML is often considered harmful for the Internet.
There's also a lot of concerns regarding Appendix C of the XHTML 1.0 Spec (dealing with
"HTML-Compatible XHTML markup").
Hope this helps
------------------------------------------------------------------------
[2007-11-12 14:49:03] rrichards@php.net
IE6 isn't fully XHTML compliant and xml declaration is perfectly valid.
Assigning to self as support for save options (including ability to suppress declaration) are
currently in progress. Not yet fully integrated into DOM extension as this requires fairly recent
libxml2 to work.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=43260
--
Edit this bug report at https://bugs.php.net/bug.php?id=43260&edit=1