views:

35

answers:

2

Hi, all!

The following is an unexpected warning message the server is giving me:

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: ID page3 already defined in Entity, line: 25 in C:\Program Files\Zend\Apache2\htdocs\joom\templates\valueTemplate\updateRecord.php on line 74 .

.

The above warning message is generated upon execution of the following code:

$html = new DOMDocument();
$html->loadHTML( $fetchedData[ 'content' ] );

.

The message is unexpected as there are no duplicate uses of 'page3' as an ID in the HTML document. 'page3', however, is used many times in the HTML document as the value of a name attribute. For example:

<li id="index00025" name="page3" class="fooBar"></li>

.

Any help on this would be wholeheartedly appreciated. Thanks in advance.

+2  A: 

This is expected behavior. In HTML, the attribute "name" introduces an id, just like the attribute "id" itself, in case the element is a (I don't know anything about libxml internals, so I don't know under which circumstances elem can be NULL).

/**
 * xmlIsID:
 * [...]
 *
 * Determine whether an attribute is of type ID. In case we have DTD(s)
 * then this is done if DTD loading has been requested. In the case
 * of HTML documents parsed with the HTML parser, then ID detection is
 * done systematically.
 * [...]
 */
int
xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
    [...]
    } else if (doc->type == XML_HTML_DOCUMENT_NODE) {
        if ((xmlStrEqual(BAD_CAST "id", attr->name)) ||
        ((xmlStrEqual(BAD_CAST "name", attr->name)) &&
        ((elem == NULL) || (xmlStrEqual(elem->name, BAD_CAST "a")))))
        return(1);
    return(0);    
    }
    [...]
}

Source: valid.c on the libxml distribution.

Artefacto
Many thanks, Artefacto!! :)
+2  A: 

Artefacto's correct. Another way to look at it -- as the HTML spec does -- is that the name and id attributes share the same namespace. So an identifier defined in one of those attributes shows up in the collection of values for the other, i.e. if you define a name="foo", foo will show up when you list all the name attributes or all the id attributes.

Source: http://www.w3.org/TR/html401/struct/links.html#h-12.2.3

Val