ID: 36379
User updated by: rele at gmx dot de
Reported By: rele at gmx dot de
-Status: No Feedback
+Status: Open
Bug Type: SimpleXML related
Operating System: Windows XP SP2
-PHP Version: 5.2CVS-2007-06-26
+PHP Version: 5.2.4
New Comment:
Here is a simplified version, which only shows the missing child nodes
(so I will check attributes again once this is working).
XPath seems to be working.
The dynamic $parent->$key[$i] access is only working for $i=0,
otherwise "Notice: Uninitialized string offset" occurs.
Reproduce code:
---------------
$test_simplexml_errors = <<<EOD
<?xml version="1.0"?>
<t>
<p>PARENT<c>CHILD</c></p>
<p><c>CHILD1</c><c> </c></p>
<p> <c>CHILD1</c><c/></p>
<p><c><d/><d/></c><c/></p>
</t>
EOD;
$simplexml = simplexml_load_string($test_simplexml_errors);
// print_r($simplexml);
foreach($simplexml as $parent) {
echo $parent->asXML(), "\n"; //text node: '", (string) $parent,
"'\n";
if( ((string) $parent) && ! array_key_exists(0, $parent))
echo "ERROR: No text child node with index 0 found\n";
$children = $parent->children();
$key = $children[0]->getName();
if(! array_key_exists($key, $parent))
echo "ERROR: No child node with key '$key' found\n";
$child_count = count($parent->xpath($key));
for($i = 0; $i < $child_count; $i++) {
if(! array_key_exists($i, $parent->$key) && ($child_count != 1 ||
(string) $parent->$key) )
echo "ERROR: No child node with index $i found\n";
// echo "child $i direct: ", $parent->c[$i]->asXML(),"\n";
// echo "child $i dynamic: ", $parent->$key[$i]->asXML(),"\n";
}
foreach($parent as $child) {
// echo ' child: ', $child->asXML(), "\n child text node: '",
(string) $child, "'\n";
if($child->xpath('text()') && ! array_key_exists(0, $child)) {
echo "ERROR: No text child element with index 0 found\n";
// echo $child->asXML(), "\n";
}
$child_count = count($child->xpath('./*'));
if($child_count) {
$children = $child->children();
$key = $children[0]->getName();
for($i = 0; $i < $child_count; $i++) {
if(! array_key_exists($i, $child->$key) && ($child_count != 1
|| (string) $child->$key) )
echo "ERROR: No sub child node with index $i found\n";
// echo "sub child $i direct: ",
$child->d[$i]->asXML(),"\n";
// echo "sub child $i variable: ",
$child->$key[$i]->asXML(),"\n";
}
}
}
}
Previous Comments:
------------------------------------------------------------------------
[2007-08-28 01:00:01] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
[2007-08-20 12:03:30] [EMAIL PROTECTED]
You're still trying to do print_r/var_dump when you were asked to test
using an iterator. Please fix your code. (And please, try make it a lot
shorter..it's very hard to read now)
------------------------------------------------------------------------
[2007-06-26 06:53:51] rele at gmx dot de
I tried the snapshot with Windows XP SP2 with my 2 examples and I am
getting exactly the same output, so nothing seems to have changed.
------------------------------------------------------------------------
[2006-07-27 05:44:23] rele at gmx dot de
I tried the code with the 5.2.0RC2-dev Win32 build (Date => Jul 27 2006
04:15:19), but it produced the same result, and $parent[0] was always
NULL, too.
In addition I had to modify the second example code from
foreach($simplexml as &$parent) {
to
foreach($simplexml as $parent) {
because it produced:
PHP Fatal error: An iterator cannot be used with foreach by reference
------------------------------------------------------------------------
[2006-07-27 02:00:36] [EMAIL PROTECTED]
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.2-win32-latest.zip
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/36379
--
Edit this bug report at http://bugs.php.net/?id=36379&edit=1