ID:               31130
 User updated by:  tom at whyscream dot net
 Reported By:      tom at whyscream dot net
 Status:           Wont fix
 Bug Type:         DOM XML related
 Operating System: Linux (gentoo)
 PHP Version:      5.0.3
 New Comment:

When I submitted the bug, I had some problems  with saveXML() that
prevented me from producing usable XHTML with it. I found out how to
work around these issues the next day, and of course I was wrong (it
was there all the time, but I missed it while checking the manual).
Sorry for bothering you :)


Previous Comments:
------------------------------------------------------------------------

[2004-12-17 07:47:42] [EMAIL PROTECTED]

It's called saveHTML and not saveXHTML for a reason  ;) saveHTML
produces HTML 4.0 and as Derick pointed out, you have to use saveXML
(which works perfectly fine for me).

If you really want to have changed that, complain to the libxml2
people. We just use their function.

------------------------------------------------------------------------

[2004-12-16 20:03:37] [EMAIL PROTECTED]

Tried ->saveXML() ?

------------------------------------------------------------------------

[2004-12-16 18:36:03] tom at whyscream dot net

Description:
------------
The HTML that is generated by DomDocument::saveHTML() (and probably
saveHTMLFile() too) does not validate as XHTML (as in '1.0
Transitional'). In stead it follows common practice for HTML4.
Since some time, it's Good Practice (TM) to use simple rules like:
- always give a value to an attribute
- close single-tag elements with a '/>' instead of '>'
 etc.

All common browsers understand this syntax, even when a HTML 4.0 DTD is
specified.

With the current implementation, it's impossible to create valid XHTML
(snippets) using the php5 DOM extension.

Reproduce code:
---------------
$doc = new DomDocument();
$input = $doc->createElement('input');
$input->setAttribute('type', 'checkbox');
$input->setAttribute('checked', 'checked');
$doc->appendChild($input);
echo $doc->saveHTML();

Expected result:
----------------
This should generate a string like:
<input type="checkbox" checked="checked" />
which is valid XHTML.

Actual result:
--------------
The generated string looks like this: 
<input type="checkbox" checked>
This code gives 2 parse errors:
- no value for attribute 'checked'
- end tag for 'input' omitted (i,e, missing the forward slash)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=31130&edit=1

Reply via email to