php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30920 SimpleXML : tags with "xs:" prefix
Submitted: 2004-11-27 17:55 UTC Modified: 2004-12-28 09:31 UTC
From: hieu at laposte dot net Assigned:
Status: Closed Package: XML related
PHP Version: 5.0.2 OS: windows xp
Private report: No CVE-ID: None
 [2004-11-27 17:55 UTC] 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
(
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-28 12:07 UTC] 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-28 20:26 UTC] 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-29 07:05 UTC] 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-12-01 20:59 UTC] 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-12-01 23:20 UTC] johannes@php.net
Please read the text and the next example from the 
article, too. 
 [2004-12-28 09:31 UTC] hieu at laposte dot net
OK i understand now. Sorry. Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 20:01:31 2024 UTC