Are duplicate IDs allowed in DOM PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prioryjim
Forum Newbie
Posts: 3
Joined: Tue Aug 03, 2010 2:12 am

Are duplicate IDs allowed in DOM PHP

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Are duplicate IDs allowed in DOM PHP

Post 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.
Post Reply