helly           Thu Nov 13 15:32:39 2003 EDT

  Added files:                 
    /php-src/ext/simplexml/tests        009.phpt 009.xml 

  Modified files:              
    /php-src/ext/simplexml      simplexml.c 
    /php-src/ext/simplexml/tests        004.phpt 
  Log:
  Fix classname, CDATA handling (semantically identical to text) and 
  iterators (Return sub elements as objects, converted to string you get 
  the text).
  
  
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.83 php-src/ext/simplexml/simplexml.c:1.84
--- php-src/ext/simplexml/simplexml.c:1.83      Mon Nov 10 15:27:16 2003
+++ php-src/ext/simplexml/simplexml.c   Thu Nov 13 15:32:37 2003
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: simplexml.c,v 1.83 2003/11/10 20:27:16 helly Exp $ */
+/* $Id: simplexml.c,v 1.84 2003/11/13 20:32:37 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -553,16 +553,15 @@
                while (node) {
                        SKIP_TEXT(node);
 
-                       _get_base_node_value(sxe, node, &value TSRMLS_CC);
-                       
                        name = (char *) node->name;
                        if (!name) {
-                               name = "CDATA";
-                               namelen = sizeof("CDATA");
+                               goto next_iter;
                        } else {
                                namelen = xmlStrlen(node->name) + 1;
                        }
 
+                       _get_base_node_value(sxe, node, &value TSRMLS_CC);
+                       
                        h = zend_hash_func(name, namelen);
                        if (zend_hash_quick_find(rv, name, namelen, h, (void **) 
&data_ptr) == SUCCESS) {
                                if (Z_TYPE_PP(data_ptr) == IS_ARRAY) {
@@ -884,7 +883,7 @@
 sxe_class_name_get(zval *object, char **class_name, zend_uint *class_name_len, int 
parent TSRMLS_DC)
 {
        *class_name = estrdup("simplexml_element");
-       *class_name_len = sizeof("simplexml_element");
+       *class_name_len = sizeof("simplexml_element")-1;
 
        return 0;
 }
@@ -1216,17 +1215,28 @@
 
 static void php_sxe_iterator_current(php_sxe_iterator *iterator TSRMLS_DC)
 {
+       xmlNodePtr      node;
+
        while (iterator->node) {
-               SKIP_TEXT(iterator->node);
+               node = iterator->node;
+
+               SKIP_TEXT(node);
+       
+               do if (node->ns) {
+                       if (node->parent->ns) {
+                               if (!xmlStrcmp(node->ns->href, 
node->parent->ns->href)) {
+                                       break;
+                               }
+                       }
+               } while (0);
        
-               _get_base_node_value(iterator->sxe, iterator->node, &iterator->data 
TSRMLS_CC);
-               
                if (!iterator->node->name) {
-                       iterator->name = "CDATA";
-                       iterator->namelen = sizeof("CDATA");
+                       goto next_iter;
                } else {
-                       iterator->namelen = xmlStrlen(iterator->node->name)+1;
-                       iterator->name = (char *) iterator->node->name;
+                       iterator->namelen = xmlStrlen(node->name)+1;
+                       iterator->name = (char *) node->name;
+                       MAKE_STD_ZVAL(iterator->data);
+                       _node_as_zval(iterator->sxe, node, iterator->data TSRMLS_CC);
                }
                break;
 next_iter:
@@ -1419,7 +1429,7 @@
 {
        php_info_print_table_start();
        php_info_print_table_header(2, "Simplexml support", "enabled");
-       php_info_print_table_row(2, "Revision", "$Revision: 1.83 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.84 $");
        php_info_print_table_row(2, "Schema support", 
 #ifdef LIBXML_SCHEMAS_ENABLED
                "enabled");
Index: php-src/ext/simplexml/tests/004.phpt
diff -u php-src/ext/simplexml/tests/004.phpt:1.3 
php-src/ext/simplexml/tests/004.phpt:1.4
--- php-src/ext/simplexml/tests/004.phpt:1.3    Sat Oct 25 20:35:56 2003
+++ php-src/ext/simplexml/tests/004.phpt        Thu Nov 13 15:32:38 2003
@@ -11,11 +11,10 @@
 
 $elem1 = $sxe->elem1;
 $elem2 = $elem1->elem2;
-echo($elem2->CDATA);
-
-echo "---Done---\n";
+var_dump(trim((string)$elem2));
 
 ?>
+===DONE===
 --EXPECT--
 simplexml_element Object
 (
@@ -27,10 +26,6 @@
 
             [elem2] => simplexml_element Object
                 (
-                    [CDATA] => simplexml_element Object
-                        (
-                        )
-
                     [elem3] => simplexml_element Object
                         (
                             [elem4] => simplexml_element Object
@@ -48,4 +43,5 @@
         )
 
 )
----Done--- 
+string(11) "CDATA block"
+===DONE===

Index: php-src/ext/simplexml/tests/009.phpt
+++ php-src/ext/simplexml/tests/009.phpt
--TEST--
SimpleXML and XPath 
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php 
$sxe = simplexml_load_file(dirname(__FILE__).'/009.xml');
foreach($sxe as $name=>$val) {
        var_dump($name);
        var_dump(get_class($val));
        var_dump(trim((string)$val));
}
?>
===DONE===
--EXPECT--
string(5) "elem1"
string(17) "simplexml_element"
string(10) "Bla bla 1."
string(6) "elem11"
string(17) "simplexml_element"
string(10) "Bla bla 2."
===DONE===

Index: php-src/ext/simplexml/tests/009.xml
+++ php-src/ext/simplexml/tests/009.xml
<?xml version='1.0'?>
<!DOCTYPE sxe SYSTEM "notfound.dtd" [
<!ENTITY % incent SYSTEM "sxe.ent">
%incent;
]>
<sxe id="elem1">
 Plain text.
 <elem1 attr1='first'>
  Bla bla 1.
  <!-- comment -->
  <elem2>
   Here we have some text data.
   <elem3>
    And here some more.
    <elem4>
     Wow once again.
    </elem4>
   </elem3>
  </elem2>
 </elem1>
 <elem11 attr2='second'>
  Bla bla 2.
 </elem11>
</sxe> 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to