Page 1 of 1

Are duplicate IDs allowed in DOM PHP

Posted: Thu Aug 05, 2010 2:49 am
by prioryjim
Not an expert in PHP DOM but have the following problem.
I have 2 tables in my page ,each with separate ids, see source.

[text]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Tab12</title>
</head>
<body>
<table id="tab1">
<tbody>
<tr>
<td id="f0"></td>
<td id="f1"></td>
</tr>
</tbody>
</table>
<table id="tab2">
<tbody>
<tr>
<td id="f0"></td>
<td id="f1"></td>
</tr>
</tbody>
</table>
</body>
</html>
[/text]

But when I load it with DOM PHP code ..

Code: Select all

<?php
        /*** a new dom object ***/
        $dom = new domDocument;
        /*** load the html into the object ***/
        $dom->loadHTMLFILE('Tab12.html');

        $str = $dom->saveHTML();
        echo $str;
?>
I get a warning

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: ID f0 already defined in Tab12.html, line: xx in

I would have though that as the ids are in separate nodes they would be OK.
But perhaps not.
Anyone know if this is correct.
Thanks Jim

Re: Are duplicate IDs allowed in DOM PHP

Posted: Thu Aug 05, 2010 6:21 am
by requinix
prioryjim wrote:I would have though that as the ids are in separate nodes they would be OK.
No.

HTML 101: IDs have to be unique throughout the entire document.