php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33376 incorrect namespaces parsing with html file
Submitted: 2005-06-17 02:39 UTC Modified: 2005-06-17 11:18 UTC
From: frederic dot lecointre at burnweb dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.0.4 OS: w2k
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: frederic dot lecointre at burnweb dot net
New email:
PHP Version: OS:

 

 [2005-06-17 02:39 UTC] frederic dot lecointre at burnweb dot net
Description:
------------
incorrect namespaces parsing with html file and DOMDocument::loadHTML
xmlns can't be a namesspace prefix!
html can have mutliple namespaces

Reproduce code:
---------------
<?php
$html_string = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:tag="http://tag.com/tag">
	<head>
		<title></title>
		<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
	</head>
<body >
  <xforms:view > 
    <tag:form id="helloForm"></tag:form>
  </xforms:view>
</body>
</html>
';

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->loadHTML($html_string);
?>

Actual result:
--------------
Warning: DOMDocument::loadHTML(): Namespace prefix xmlns of attribute xforms is not defined in Entity, line: 3 

Warning: DOMDocument::loadHTML(): Namespace prefix xmlns of attribute tag is not defined in Entity, line: 3 

Notice: DOMDocument::loadHTML(): Namespace prefix xforms is not defined in Entity, line: 9 

Warning: DOMDocument::loadHTML(): Tag xforms:view invalid in Entity, line: 9 

Notice: DOMDocument::loadHTML(): Namespace prefix tag is not defined in Entity, line: 10 

Warning: DOMDocument::loadHTML(): Tag tag:form invalid in Entity, line: 10 in 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-17 10:47 UTC] chregu@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

loadHTML is for loading HTML4 documents, which per standard 
don't know anything about namespaces, therefore the default 
xmlns namespace isn't set. If you want to load namespaced and 
well-formed documents, use loadXML() (which works perfectly 
fine on your example)
 [2005-06-17 10:58 UTC] frederic dot lecointre at burnweb dot net
hi,

perfectly ?
<?php
$html_string = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:tag="http://tag.com/tag">
<head>
<title>fr&eacute;</title>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1" />
</head>
<body >
  <xforms:view > 
    <tag:form id="helloForm"></tag:form>
  </xforms:view>
</body>
</html>
';

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->loadXML($html_string);
?>
 return:
Warning: DOMDocument::loadXML(): Entity 'eacute' not defined in Entity, line: 8

loadHTML can't parse xhtml, ok ... in other hand loadXML can't parse dtd declared in doctype...
what's the solution ?
 [2005-06-17 11:18 UTC] frederic dot lecointre at burnweb dot net
hi,

well bogus!
is it possible to add this in documentation ?
--
to parse valid xhtml document use DOMdocument::loadXML and  set resolveExternals to TRUE. For better performance, import locally the dtd file with the entity declaration file.

<?php
$html_string = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>fr&eacute;</title>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1" />
</head>
<body >
</body>
</html>
';

$doc = new DOMDocument('1.0', 'iso-8859-1');
$doc->resolveExternals = TRUE;
$doc->loadXML($html_string);
?>
--

thanks and sorry.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 03:01:29 2024 UTC