#30920 [Bgs]: SimpleXML : tags with "xs:" prefix
| From: | chregu@php.net | Date: | Mon, 29 Nov 2004 06:05:35 +0000 |
| Subject: | #30920 [Bgs]: SimpleXML : tags with "xs:" prefix | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-69592@lists.php.net to get a copy of this message | ||
ID: 30920
Updated by: chregu@php.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:
read the article mentioned above at zend, especially the part about
namespaces.. It's not a bug. You have to use the method "children()"
Previous Comments:
------------------------------------------------------------------------
[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