|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 11 08:00:01 2025 UTC |
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