php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47612 DOM Xml seems broken when used with DTD
Submitted: 2009-03-10 08:36 UTC Modified: 2009-03-11 08:25 UTC
From: murlock42 at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3CVS-2009-03-10 (snap) OS: Linux Debian Lenny
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 + 19 = ?
Subscribe to this entry?

 
 [2009-03-10 08:36 UTC] murlock42 at gmail dot com
Description:
------------
When I use a XML file with DTD, the root node doesn't have any children (but xpath query works) and if I removed the DTD, the DOM seems ok

Reproduce code:
---------------
function test( $filename ) { 
  $xml = new DOMDocument();
  $xml->load( $filename, LIBXML_NOBLANKS );

  echo "\n$filename\n";
  echo "Root of XML : " . $xml->firstChild->nodeName . "\n";
  echo "First child of XML Root : " . $xml->firstChild->firstChild->nodeName . "\n";

  $xpath = new DOMXpath( $xml );

  echo "result of /mame/game xpath query : \n";
  $r = $xpath->query("/mame/game");
  for( $i=0; $i<$r->length; $i++ ) { 
    echo $r->item($i)->nodeName . "\n";
  }

}
test( "file_without_dtd.xml" );
test( "file_with_dtd.xml" );



Expected result:
----------------
with the two XML files: 
file_without_dtd.xml
Root of XML : mame
First child of XML Root : game
result of /mame/game xpath query : 
game

file_with_dtd.xml
Root of XML : mame
First child of XML Root : game
result of /mame/game xpath query : 
game


Actual result:
--------------
file_without_dtd.xml
Root of XML : mame
First child of XML Root : game
result of /mame/game xpath query : 
game

file_with_dtd.xml
Root of XML : mame
First child of XML Root : 
result of /mame/game xpath query : 
game


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-10 08:39 UTC] murlock42 at gmail dot com
The url for the XML files : 
http://murlock.org/file_with_dtd.xml
http://murlock.org/file_without_dtd.xml

Thanks,
 [2009-03-10 15:08 UTC] chregu@php.net
The root node is always at

$xml->documentElement and not always at $xml->firstChild.

Change that and your problem should be slved




 [2009-03-11 08:25 UTC] murlock42 at gmail dot com
Ok, it's work with documentElement, 
I found doc unclear: instead of 'This is a convenience attribute that allows direct access to the child node that is the document element of the document.', the doc should be something like that 'User must use this to access to the child node that is the document element of the document.'

But now, I've another weird problem (bug ? or my fault ?) with DTD : 


function test( $filename ) {
  $xml = new DOMDocument();
  $xml->load( $filename, LIBXML_NOBLANKS );

  $node = $xml->documentElement->firstChild;

  if ( $node->attributes->getNamedItem("isbios") )
    echo $node->attributes->getNamedItem("isbios")->nodeValue . "\n";
  else
    echo "no attribute isbios\n";
}
test( "file_without_dtd.xml" );
test( "file_with_dtd.xml" );

:

no attribute isbios

Warning: DOMNamedNodeMap::getNamedItem(): Unsupported node type: 16 in /home/murlock/perso/mameutils/bad.php on line 9
no attribute isbios
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 22:01:33 2024 UTC