1

My PHP script tries to load a valid XHTML5 file, do some manipulations using the DOM, and output it to the client.

However, in order to use document::getElementById(), I have to validate the document first.

The PHP script can not do so because there is no DTD in HTML5. How can I do this?

hakre
  • 193,403
  • 52
  • 435
  • 836
Michael Tsang
  • 678
  • 5
  • 16

1 Answers1

1

I have just found a hack which allow me to use document::getElementById() without validation:

// HACK
foreach ($document->getElementsByTagName('*') as $element) {
    try {
        $element->setIdAttribute('id', TRUE);
    } catch (Exception $e) {
    }
}
Michael Tsang
  • 678
  • 5
  • 16
  • That "hack" has been outlined in a previous question. If that really solves your issue, I suggest to close against it. E.g. (as outlined in) [How do I parse partial HTML?](http://stackoverflow.com/q/1933631/367456) – hakre Jun 20 '13 at 09:02
  • Or as outlined here: [PHP HTML DomDocument getElementById problems](http://stackoverflow.com/q/3391942/367456) or here: [how to set id of an element using PHP dom?](http://stackoverflow.com/q/3617825/367456) or here: [help with DOMDocument class in php](http://stackoverflow.com/q/2441208/367456) - Also related: [Simplify PHP DOM XML parsing - how?](http://stackoverflow.com/q/3405117/367456) – hakre Jun 20 '13 at 09:21