Re: DOMDocument saveHTML() configurable?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michael A. Peters wrote:
The $dom->saveHTML() function does a pretty good job of knowing what tags are not closed - IE it does <br>, <meta>, <param>, etc. correctly.

Is there a way to add a tag without children to it's database?

Specifically I'm talking about the new <source> tag from HTML 5 that is being used to embed ogg/mp4 audio and video files.

Put it in a dom document object and spit it out with saveHTML() and you get <source src="foo.ogg" type="video/ogg"></source> which is harmless but technically incorrect.

I know html tidy allows you to define new childless nodes and sending the output through tidy will then fix it, but I can't seem to find a way to to it with DOMDocument so that you don't need to send it through tidy before sending to the client.

If you use saveXML instead of saveHTML, it will self-close empty tags. Then for any tags that should not be self-closed, you just need to pass an empty value as the second parameter of createElement.

$doc->createElement('source');
...
echo $doc->saveXML(); // <source />

$doc->createElement('div', '');
...
echo $doc->saveXML(); // <div></div>

That's the way I'd do it. Hope that helps.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux