#30920 [Bgs->Csd]: SimpleXML : tags with "xs:" prefix
| From: | hieu at laposte dot net | Date: | Tue, 28 Dec 2004 08:31:18 +0000 |
| Subject: | #30920 [Bgs->Csd]: SimpleXML : tags with "xs:" prefix | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-71150@lists.php.net to get a copy of this message | ||
ID: 30920
User updated by: hieu at laposte dot net
Reported By: hieu at laposte dot net
-Status: Bogus
+Status: Closed
Bug Type: XML related
Operating System: windows xp
PHP Version: 5.0.2
New Comment:
OK i understand now. Sorry. Thank you.
Previous Comments:
------------------------------------------------------------------------
[2004-12-01 23:20:46] johannes@php.net
Please read the text and the next example from the
article, too.
------------------------------------------------------------------------
[2004-12-01 20:59:07] hieu at laposte dot net
I use the example found in the article above, and i get the error
again. For me it is a bug.
syndic.xml =
<?xml version="1.0"?>
<entries xmlns:blog="http://www.edwardbear.org/serendipity/">
<blog:entry>
<blog:name>RPROF - Regular Expression Profiler</blog:name>
</blog:entry>
<blog:entry>
<blog:name>Advanced PHP Programming</blog:name>
</blog:entry>
</entries>
<?php
$entries = simplexml_load_file('syndic.xml');
foreach ($entries->blog->entry as $entry) {
printf("%s\n", $entry->name);
}
?>
What i only get is :
Warning: Invalid argument supplied for foreach() in
c:\home\www\ado\txml.php on line 3
------------------------------------------------------------------------
[2004-11-29 07:05:32] chregu@php.net
read the article mentioned above at zend, especially the part about
namespaces.. It's not a bug. You have to use the method "children()"
------------------------------------------------------------------------
[2004-11-28 20:26:04] hieu at laposte dot net
print_r doesn't work correctly with simplexml, okay... but please read
this new code, it doesn't use print_r and shows the same bug :
bug.xsd =
<?xml version="1.0" encoding="utf-16" ?>
<xs:schema id="bug" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="dataset">
</xs:element>
</xs:schema>
$xml = simplexml_load_file("bug.xsd");
$elt = $xml->element;
$attr = (string) $elt['name'];
echo $attr;
=> nothing is printed...
if i remove the "xs:" prefix in the xsd file, this same code displays :
"dataset"
------------------------------------------------------------------------
[2004-11-28 12:07:14] chregu@php.net
print_r and var_dump don't work reliably on simplexml objects... do
*not* use them or even rely on them...
And see http://www.zend.com/php5/articles/php5-simplexml.php
for more
info about SimpleXML and Namespaces
------------------------------------------------------------------------
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/30920
--
Edit this bug report at http://bugs.php.net/?id=30920&edit=1