Re: [PHP4BETA] XML DOM oddity?
| From: | Paul DuBois | Date: | Thu, 02 Mar 2000 01:58:32 +0000 |
| Subject: | Re: [PHP4BETA] XML DOM oddity? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-11303@lists.php.net to get a copy of this message | ||
I've tracked the problem below that I reported a few days ago to
a problem in libxml. It's not a PHP problem at all. Sorry for
the false alarm.
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))-- Paul DuBois, paul@snake.netprint ("xmldoc: document okay\n");elseprint ("xmldoc: document parse error\n");if ($dom = xmltree($xmlstr))print ("xmltree: document okay\n");elseprint ("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