Doc #63679 [NEW]: "Dealing with XML errors" documentation example is wrong
| From: | toby at caboteria dot org | Date: | Mon, 03 Dec 2012 22:26:03 +0000 |
| Subject: | Doc #63679 [NEW]: "Dealing with XML errors" documentation example is wrong | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-9255@lists.php.net to get a copy of this message | ||
From: toby at caboteria dot org
Operating system: n/a
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:"Dealing with XML errors" documentation example is wrong
Description:
------------
There are at least two cases where the example code on the "Dealing with
XML errors" page[0] won't work correctly. The first is mentioned in one of
the notes[1]: a document with an empty root node will show up as an error,
even if it parses correctly. The second is if the nodes just below the
document node are in a different namespace.
I recommend using
if (libxml_get_errors()) {
instead of the existing code.
[0] http://php.net/manual/en/simplexml.examples-errors.php
[1] http://php.net/manual/en/simplexml.examples-errors.php#96416
Test script:
---------------
First case:
<?php
libxml_use_internal_errors(true);
$sxe = simplexml_load_string("<?xml version='1.0'?><not_broken/>");
if (!$sxe) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
?>
Second case:
<?php
libxml_use_internal_errors(true);
$sxe = simplexml_load_string("<?xml version='1.0'?><not_broken
xmlns:m='urn:m'><m:foo></m:foo></not_broken>");
if (!$sxe) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
?>
Expected result:
----------------
Empty page.
Actual result:
--------------
Failed loading XML
--
Edit bug report at https://bugs.php.net/bug.php?id=63679&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63679&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63679&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63679&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=63679&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=63679&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=63679&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=63679&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=63679&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=63679&r=support
Expected behavior: https://bugs.php.net/fix.php?id=63679&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=63679&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=63679&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=63679&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63679&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=63679&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=63679&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=63679&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63679&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=63679&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=63679&r=mysqlcfg