If I try to load an HTML document into PHP DOM I get an error along the lines of:
Error DOMDocument::loadHTML() [domdocument.loadhtml]: ID someAnchor already
If you are loading XML files (that's the case, XHTML is XML), then you should use DOMDocument::loadXML(), not DOMDocument::loadHTML().
In HTML, both name
and id
introduce an ID. So you are repeating the id "someAnchor", hence the error.
However, the W3C validator allows repeated IDs in the form you show <a id="someAnchor" name="someAnchor"></a>
. This may be a bug of libmxl2.
In this bug report for libxml2, a user proposes a patch to only consider the name
attribute as an ID:
According to the HTML and XHTML specs, only the a element's name attribute shares name space with id attributes. For some of the elements it can be argued that multiple instances with the same name don't make sense, but they should nevertheless not be considered in the same namespace as other elements' id attributes.
See http://www.zvon.org/xxl/xhtmlReference/Output/Strict/attr_name.html for all the elements that take name attributes and their semantics.