#30920 [Bgs]: SimpleXML : tags with "xs:" prefix
| From: | hieu at laposte dot net | Date: | Wed, 01 Dec 2004 19:59:09 +0000 |
| Subject: | #30920 [Bgs]: SimpleXML : tags with "xs:" prefix | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-69698@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
Bug Type: XML related
Operating System: windows xp
PHP Version: 5.0.2
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
[2004-11-27 17:55:59] hieu at laposte dot net
Description:
------------
When the xml file contains this "xs:" prefix, the file is not correctly
parsed.
Reproduce code:
---------------
The XML file is :
<?xml version="1.0" encoding="utf-16" ?>
<xs:schema id="ds" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="ds" msdata:IsDataSet="true"
msdata:Locale="fr-FR">
<complexType>
...
</xs:element>
</xs:schema>
Php 5 code :
$oXml = simplexml_load_file($sFileName);
print_r($oXml->element);
// doesn't work, nothing printed...
PS : this code works correctly :
$oXml = simplexml_load_file($sFileName);
$aXml = get_object_vars($oXml);
print_r($aXml['element']);
// ok i can now access the "element".
Expected result:
----------------
SimpleXMLElement Object
(
[complexType] => SimpleXMLElement Object
(
.....
)
)
Actual result:
--------------
SimpleXMLElement Object
(
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30920&edit=1