XML DOM oddity?
| From: | Paul DuBois | Date: | Sun, 27 Feb 2000 00:29:33 +0000 |
| Subject: | XML DOM oddity? | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-11061@lists.php.net to get a copy of this message | ||
php 4.0b4-dev
I have a short test script that does nothing but parse an XML string
a couple of ways and report success or failure:
#! /usr/local/bin/php4 -q
<?php
$xmlstr = "<?xml version='1.0'?><root></root>";
if ($dom = xmldoc($xmlstr))
print ("xmldoc: document okay\n");
else
print ("xmldoc: document parse error\n");
if ($dom = xmltree($xmlstr))
print ("xmltree: document okay\n");
else
print ("xmltree: document parse error\n");
?>
When invoked as shown above, the result is:
Entity: line 1: error: End tag : expected '>'
<?xml version='1.0'?><root></root
^xmldoc: document parse error Entity: line 1: error: End tag : expected '>' <?xml version='1.0'?><root></root
^xmltree: document parse error However, if I add a space at the end of the $xmlstr, like so: $xmlstr = "<?xml version='1.0'?><root></root> "; The result is: xmldoc: document okay xmltree: document okay It appears that the DOM parsing has a problem when the closing '>' of the root element is the final character of the string. I get a failure of a different sort when using <root/> to signify an empty root element: $xmlstr = "<?xml version='1.0'?><root/>"; The result is: Entity: line 1: error: error parsing attribute name <?xml version='1.0'?><root/
^Entity: line 1: error: xmlParseStartTag: problem parsing attributes <?xml version='1.0'?><root/
^Entity: line 1: error: Couldn't find end of Start Tag <root/ <?xml version='1.0'?><root/
^Entity: line 1: error: Extra content at the end of the document <?xml version='1.0'?><root/
^xmldoc: document parse error Entity: line 1: error: error parsing attribute name <?xml version='1.0'?><root/
^Entity: line 1: error: xmlParseStartTag: problem parsing attributes <?xml version='1.0'?><root/
^Entity: line 1: error: Couldn't find end of Start Tag <root/ <?xml version='1.0'?><root/
^Entity: line 1: error: Extra content at the end of the document <?xml version='1.0'?><root/
^xmltree: document parse error If I add a space at the end of $xmlstr, like so: $xmlstr = "<?xml version='1.0'?><root/> "; The result is: xmldoc: document okay xmltree: document okay I guess now I know why the test $xmlstr in tests/testdom ends with a space :-), but should this be happening? Substituting a newline for a terminating space in the examples shown above also makes the errors go away. I'm *guessing* this problem is something in the DOM support, because if I send similar strings into the PHP 3 lower-level XML parsing routines, I don't get any errors. -- Paul DuBois, paul@snake.net