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.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.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.
$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

