helly           Sun Feb 26 23:14:45 2006 UTC

  Added files:                 (Branch: PHP_5_1)
    /php-src/ext/simplexml/tests        026.phpt 027.phpt 028.phpt 

  Modified files:              
    /php-src/ext/simplexml      php_simplexml.h simplexml.c 
    /php-src/ext/simplexml/tests        bug35785.phpt 
  Log:
  - Synch with head
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/php_simplexml.h?r1=1.20.2.1&r2=1.20.2.2&diff_format=u
Index: php-src/ext/simplexml/php_simplexml.h
diff -u php-src/ext/simplexml/php_simplexml.h:1.20.2.1 
php-src/ext/simplexml/php_simplexml.h:1.20.2.2
--- php-src/ext/simplexml/php_simplexml.h:1.20.2.1      Sun Jan  1 12:50:13 2006
+++ php-src/ext/simplexml/php_simplexml.h       Sun Feb 26 23:14:45 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_simplexml.h,v 1.20.2.1 2006/01/01 12:50:13 sniper Exp $ */
+/* $Id: php_simplexml.h,v 1.20.2.2 2006/02/26 23:14:45 helly Exp $ */
 
 #ifndef PHP_SIMPLEXML_H
 #define PHP_SIMPLEXML_H
@@ -53,6 +53,13 @@
 #endif
 PHP_MINFO_FUNCTION(simplexml);
 
+typedef enum {
+       SXE_ITER_NONE     = 0,
+       SXE_ITER_ELEMENT  = 1,
+       SXE_ITER_CHILD    = 2,
+       SXE_ITER_ATTRLIST = 3
+} SXE_ITER;
+
 typedef struct {
        zend_object zo;
        php_libxml_node_ptr *node;
@@ -63,16 +70,12 @@
                int                   itertype;
                char                  *name;
                char                  *nsprefix;
-               int                   type;
+               SXE_ITER              type;
                zval                  *data;
        } iter;
+       zval *tmp;
 } php_sxe_object;
 
-#define SXE_ITER_NONE 0
-#define SXE_ITER_ELEMENT 1
-#define SXE_ITER_CHILD 2
-#define SXE_ITER_ATTRLIST 3
-
 #ifdef ZTS
 #define SIMPLEXML_G(v) TSRMG(simplexml_globals_id, zend_simplexml_globals *, v)
 #else
http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/simplexml.c?r1=1.151.2.11&r2=1.151.2.12&diff_format=u
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.151.2.11 
php-src/ext/simplexml/simplexml.c:1.151.2.12
--- php-src/ext/simplexml/simplexml.c:1.151.2.11        Mon Feb  6 10:52:34 2006
+++ php-src/ext/simplexml/simplexml.c   Sun Feb 26 23:14:45 2006
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: simplexml.c,v 1.151.2.11 2006/02/06 10:52:34 tony2001 Exp $ */
+/* $Id: simplexml.c,v 1.151.2.12 2006/02/26 23:14:45 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -130,10 +130,10 @@
 }
 /* }}} */
 
-static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, 
xmlNodePtr node) /* {{{ */
+static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, 
xmlNodePtr node, long *cnt) /* {{{ */
 {
        long nodendx = 0;
-
+       
        if (sxe->iter.type == SXE_ITER_NONE) {
                return NULL;
        }
@@ -151,12 +151,15 @@
 next_iter:
                node = node->next;
        }
+       
+       if (cnt) {
+               *cnt = nodendx;
+       }
 
        return node;
 }
 /* }}} */
 
-#if SXE_ELEMENT_BY_NAME
 static xmlNodePtr sxe_find_element_by_name(php_sxe_object *sxe, xmlNodePtr 
node, char *name TSRMLS_DC) /* {{{ */
 {
        while (node) {
@@ -172,7 +175,7 @@
        return NULL;
 } /* }}} */
 
-static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr 
node, char **name, int *type TSRMLS_DC) /* {{{ */
+static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr 
node, char **name, SXE_ITER *type TSRMLS_DC) /* {{{ */
 {
        int         orgtype;
        xmlNodePtr  orgnode = node;
@@ -219,7 +222,6 @@
        return NULL;
 }
 /* }}} */
-#endif /* SXE_ELEMENT_BY_NAME */
 
 /* {{{ sxe_prop_dim_read()
  */
@@ -231,7 +233,7 @@
        xmlNodePtr      node;
        xmlAttrPtr      attr = NULL;
        zval            tmp_zv;
-       int                             nodendx = 0;
+       int             nodendx = 0;
        int             test = 0;
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
@@ -303,7 +305,7 @@
                                if (sxe->iter.type == SXE_ITER_CHILD) {
                                        node = php_sxe_get_first_node(sxe, node 
TSRMLS_CC);
                                }
-                               node = sxe_get_element_by_offset(sxe, 
Z_LVAL_P(member), node);
+                               node = sxe_get_element_by_offset(sxe, 
Z_LVAL_P(member), node, NULL);
                                if (node) {
                                        _node_as_zval(sxe, node, return_value, 
SXE_ITER_NONE, NULL, sxe->iter.nsprefix TSRMLS_CC);
                                }
@@ -329,6 +331,10 @@
        if (member == &tmp_zv) {
                zval_dtor(&tmp_zv);
        }
+       if (Z_TYPE_P(return_value) == IS_NULL) {
+               zval_ptr_dtor(&return_value);
+               return_value = &EG(uninitialized_zval);
+       }
 
        return return_value;
 }
@@ -356,6 +362,11 @@
 {
        zval value_copy;
 
+       if (!value)
+       {
+               xmlNodeSetContentLen(node, "", 0);
+               return;
+       }
        switch (Z_TYPE_P(value)) {
                case IS_LONG:
                case IS_BOOL:
@@ -383,18 +394,20 @@
 
 /* {{{ sxe_property_write()
  */
-static void sxe_prop_dim_write(zval *object, zval *member, zval *value, 
zend_bool elements, zend_bool attribs TSRMLS_DC)
+static void sxe_prop_dim_write(zval *object, zval *member, zval *value, 
zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode TSRMLS_DC)
 {
        php_sxe_object *sxe;
        char           *name;
        xmlNodePtr      node;
        xmlNodePtr      newnode = NULL;
+       xmlNodePtr      mynode;
        xmlNodePtr              tempnode;
        xmlAttrPtr      attr = NULL;
        int             counter = 0;
        int             is_attr = 0;
        int                             nodendx = 0;
        int             test = 0;
+       long            cnt;
        zval            tmp_zv, trim_zv;
 
        if (!member) {
@@ -444,9 +457,31 @@
                attr = (xmlAttrPtr)node;
                test = sxe->iter.name != NULL;
        } else if (sxe->iter.type != SXE_ITER_CHILD) {
+               mynode = node;
                node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
                attr = node ? node->properties : NULL;
                test = 0;
+               if (attribs && !node && sxe->iter.type == SXE_ITER_ELEMENT) {
+                       node = xmlNewChild(mynode, mynode->ns, sxe->iter.name, 
NULL);
+                       attr = node->properties;
+               }
+       }
+
+       mynode = node;
+
+       if (value) {
+               switch (Z_TYPE_P(value)) {
+                       case IS_LONG:
+                       case IS_BOOL:
+                       case IS_DOUBLE:
+                       case IS_NULL:
+                               convert_to_string(value);
+                               break;
+                       case IS_STRING:
+                               break;
+                       default:
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "It 
is not yet possible to assign complex types to %s", attribs ? "attributes" : 
"properties");
+               }
        }
 
        if (node) {
@@ -478,7 +513,7 @@
 
                if (elements) {
                        if (Z_TYPE_P(member) == IS_LONG) {
-                               newnode = sxe_get_element_by_offset(sxe, 
Z_LVAL_P(member), node);
+                               newnode = sxe_get_element_by_offset(sxe, 
Z_LVAL_P(member), node, &cnt);
                                if (newnode) {
                                        ++counter;
                                }
@@ -502,34 +537,35 @@
                        if (is_attr) {
                                newnode = (xmlNodePtr) attr;
                        }
-                       while ((tempnode = (xmlNodePtr) newnode->children)) {
-                               xmlUnlinkNode(tempnode);
-                               php_libxml_node_free_resource((xmlNodePtr) 
tempnode TSRMLS_CC);
+                       if (value) {
+                               while ((tempnode = (xmlNodePtr) 
newnode->children)) {
+                                       xmlUnlinkNode(tempnode);
+                                       
php_libxml_node_free_resource((xmlNodePtr) tempnode TSRMLS_CC);
+                               }
+                               change_node_zval(newnode, value TSRMLS_CC);
                        }
-                       change_node_zval(newnode, value TSRMLS_CC);
                } else if (counter > 1) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot 
assign to an array of nodes (duplicate subnodes or attr detected)");
-               } else {
-                       if (attribs) {
-                               switch (Z_TYPE_P(value)) {
-                                       case IS_LONG:
-                                       case IS_BOOL:
-                                       case IS_DOUBLE:
-                                       case IS_NULL:
-                                               convert_to_string(value);
-                                       case IS_STRING:
-                                               newnode = 
(xmlNodePtr)xmlNewProp(node, name, Z_STRVAL_P(value));
-                                               break;
-                                       default:
-                                               php_error_docref(NULL 
TSRMLS_CC, E_WARNING, "It is not yet possible to assign complex types to 
attributes");
+               } else if (elements) {
+                       if (!node) {
+                               newnode = xmlNewTextChild(mynode, mynode->ns, 
name, value ? Z_STRVAL_P(value) : NULL);
+                       } else if (Z_TYPE_P(member) == IS_LONG) {
+                               if (cnt < Z_LVAL_P(member)) {
+                                       php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Cannot add element %s number %ld when only %ld such elements 
exist", mynode->name, Z_LVAL_P(member), cnt);
                                }
+                               newnode = xmlNewTextChild(mynode->parent, 
mynode->ns, mynode->name, value ? Z_STRVAL_P(value) : NULL);
                        }
+               } else if (attribs) {
+                       newnode = (xmlNodePtr)xmlNewProp(node, name, value ? 
Z_STRVAL_P(value) : NULL);
                }
        }
 
        if (member == &tmp_zv) {
                zval_dtor(&tmp_zv);
        }
+       if (pnewnode) {
+               *pnewnode = newnode;
+       }
 }
 /* }}} */
 
@@ -537,7 +573,7 @@
  */
 static void sxe_property_write(zval *object, zval *member, zval *value 
TSRMLS_DC)
 {
-       sxe_prop_dim_write(object, member, value, 1, 0 TSRMLS_CC);
+       sxe_prop_dim_write(object, member, value, 1, 0, NULL TSRMLS_CC);
 }
 /* }}} */
 
@@ -545,7 +581,37 @@
  */
 static void sxe_dimension_write(zval *object, zval *offset, zval *value 
TSRMLS_DC)
 {
-       sxe_prop_dim_write(object, offset, value, 0, 1 TSRMLS_CC);
+       sxe_prop_dim_write(object, offset, value, 0, 1, NULL TSRMLS_CC);
+}
+/* }}} */
+
+static zval** sxe_property_get_adr(zval *object, zval *member TSRMLS_DC) /* 
{{{ */
+{
+       php_sxe_object *sxe;
+       xmlNodePtr      node;
+       zval           *return_value;
+       char           *name;
+       SXE_ITER        type;
+
+       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+
+       GET_NODE(sxe, node);
+       convert_to_string(member);
+       name = Z_STRVAL_P(member);
+       node = sxe_get_element_by_name(sxe, node, &name, &type TSRMLS_CC);
+       if (!node) {
+               sxe_prop_dim_write(object, member, NULL, 1, 0, &node TSRMLS_CC);
+               type = SXE_ITER_NONE;
+               name = NULL;
+       }
+       MAKE_STD_ZVAL(return_value);
+       _node_as_zval(sxe, node, return_value, type, name, sxe->iter.nsprefix 
TSRMLS_CC);
+
+       sxe = php_sxe_fetch_object(return_value TSRMLS_CC);
+       sxe->tmp = return_value;
+       return_value->is_ref  = 1;
+
+       return &sxe->tmp;
 }
 /* }}} */
 
@@ -554,7 +620,6 @@
 static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, 
zend_bool elements, zend_bool attribs TSRMLS_DC)
 {
        php_sxe_object *sxe;
-       char           *name;
        xmlNodePtr      node;
        xmlAttrPtr      attr = NULL;
        int                             exists = 0;
@@ -562,8 +627,6 @@
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
 
-       name = Z_STRVAL_P(member);
-
        GET_NODE(sxe, node);
 
        if (Z_TYPE_P(member) == IS_LONG) {
@@ -591,7 +654,7 @@
        if (node) {
                if (attribs) {
                        while (attr) {
-                               if ((!test || !xmlStrcmp(attr->name, 
sxe->iter.name)) && !xmlStrcmp(attr->name, name) && match_ns(sxe, (xmlNodePtr) 
attr, sxe->iter.nsprefix)) {
+                               if ((!test || !xmlStrcmp(attr->name, 
sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, 
(xmlNodePtr) attr, sxe->iter.nsprefix)) {
                                        exists = 1;
                                        break;
                                }
@@ -605,7 +668,7 @@
                                if (sxe->iter.type == SXE_ITER_CHILD) {
                                        node = php_sxe_get_first_node(sxe, node 
TSRMLS_CC);
                                }
-                               node = sxe_get_element_by_offset(sxe, 
Z_LVAL_P(member), node);
+                               node = sxe_get_element_by_offset(sxe, 
Z_LVAL_P(member), node, NULL);
                        }
                        else {
                                zval tmp_zv;
@@ -628,7 +691,7 @@
                                if (member == &tmp_zv) {
                                        zval_dtor(&tmp_zv);
                                }
-            }
+                       }
                        if (node) {
                                exists = 1;
                        }
@@ -680,7 +743,7 @@
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                attribs = 1;
                elements = 0;           
-       node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+               node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
                attr = (xmlAttrPtr)node;
                test = sxe->iter.name != NULL;
        } else {
@@ -1000,7 +1063,7 @@
                                _node_as_zval(sxe, nodeptr->parent, value, 
SXE_ITER_NONE, NULL, NULL TSRMLS_CC);
                        } else if (nodeptr->type == XML_ATTRIBUTE_NODE) {
                                _node_as_zval(sxe, nodeptr->parent, value, 
SXE_ITER_ATTRLIST, (char*)nodeptr->name, NULL TSRMLS_CC);
-                       } else  {
+                       } else {
                                _node_as_zval(sxe, nodeptr, value, 
SXE_ITER_NONE, NULL, NULL TSRMLS_CC);
                        }
 
@@ -1215,7 +1278,7 @@
 }
 /* }}} */
 
-/* {{{ proto object SimpleXMLElement::children()
+/* {{{ proto object SimpleXMLElement::children([string ns])
    Finds children of given node */
 SXE_METHOD(children)
 {
@@ -1242,6 +1305,23 @@
 }
 /* }}} */
 
+/* {{{ proto object SimpleXMLElement::getName()
+   Finds children of given node */
+SXE_METHOD(getName)
+{
+       php_sxe_object *sxe;
+       xmlNodePtr      node;
+       int             namelen;
+
+       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+
+       GET_NODE(sxe, node);
+       
+       namelen = xmlStrlen(node->name);
+       RETURN_STRINGL((char*)node->name, namelen, 1);
+}
+/* }}} */
+
 /* {{{ proto array SimpleXMLElement::attributes([string ns])
    Identifies an element's attributes */
 SXE_METHOD(attributes)
@@ -1396,7 +1476,7 @@
        sxe_property_write,
        sxe_dimension_read,
        sxe_dimension_write,
-       NULL,
+       sxe_property_get_adr,
        sxe_get_value,                  /* get */
        NULL,
        sxe_property_exists,
@@ -1420,7 +1500,7 @@
        sxe_property_write,
        sxe_dimension_read,
        sxe_dimension_write,
-       NULL,
+       sxe_property_get_adr,
        sxe_get_value,                  /* get */
        NULL,
        sxe_property_exists,
@@ -1495,6 +1575,10 @@
                xmlFree(sxe->iter.nsprefix);
                sxe->iter.nsprefix = NULL;
        }
+       if (sxe->tmp) {
+               zval_ptr_dtor(&sxe->tmp);
+               sxe->tmp = NULL;
+       }
 }
 /* }}} */
 
@@ -1961,11 +2045,12 @@
        SXE_ME(__construct,            NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) /* 
must be called */
        SXE_ME(asXML,                  NULL, ZEND_ACC_PUBLIC)
        SXE_ME(xpath,                  NULL, ZEND_ACC_PUBLIC)
-       SXE_ME(registerXPathNamespace,      NULL, ZEND_ACC_PUBLIC)
+       SXE_ME(registerXPathNamespace, NULL, ZEND_ACC_PUBLIC)
        SXE_ME(attributes,             NULL, ZEND_ACC_PUBLIC)
-       SXE_ME(children,                           NULL, ZEND_ACC_PUBLIC)
+       SXE_ME(children,               NULL, ZEND_ACC_PUBLIC)
        SXE_ME(getNamespaces,          NULL, ZEND_ACC_PUBLIC)
        SXE_ME(getDocNamespaces,       NULL, ZEND_ACC_PUBLIC)
+       SXE_ME(getName,                NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 
@@ -2018,7 +2103,7 @@
 {
        php_info_print_table_start();
        php_info_print_table_header(2, "Simplexml support", "enabled");
-       php_info_print_table_row(2, "Revision", "$Revision: 1.151.2.11 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.151.2.12 $");
        php_info_print_table_row(2, "Schema support",
 #ifdef LIBXML_SCHEMAS_ENABLED
                "enabled");
http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/bug35785.phpt?r1=1.1.2.3&r2=1.1.2.4&diff_format=u
Index: php-src/ext/simplexml/tests/bug35785.phpt
diff -u php-src/ext/simplexml/tests/bug35785.phpt:1.1.2.3 
php-src/ext/simplexml/tests/bug35785.phpt:1.1.2.4
--- php-src/ext/simplexml/tests/bug35785.phpt:1.1.2.3   Fri Dec 23 20:32:15 2005
+++ php-src/ext/simplexml/tests/bug35785.phpt   Sun Feb 26 23:14:45 2006
@@ -3,21 +3,24 @@
 --FILE--
 <?php
 
-$options["database"] = "xmldatabase";
 $xml = simplexml_load_string("<root></root>");
-$count = count($xml->posts) + 1;
-$xml->bla->posts[$count]->name = $_POST["name"];
+$xml->bla->posts->name = "FooBar";
+echo $xml->asXML();
+
+echo "===FAIL===\n";
+
+$xml = simplexml_load_string("<root></root>");
+$count = count($xml->bla->posts);
+var_dump($count);
+$xml->bla->posts[++$count]->name = "FooBar";
 echo $xml->asXML();
 ?>
 ===DONE===
 <?php exit(0); __halt_compiler(); ?>
 --EXPECTF--
-
-Notice: Undefined index:  name in %sbug35785.php on line %d
-
-Strict Standards: Creating default object from empty value in %sbug35785.php 
on line %d
-
-Warning: Attempt to assign property of non-object in %sbug35785.php on line %d
 <?xml version="1.0"?>
-<root/>
-===DONE===
+<root><bla><posts><name>FooBar</name></posts></bla></root>
+===FAIL===
+int(0)
+
+Fatal error: Objects used as arrays in post/pre increment/decrement must 
return values by reference in %sext/simplexml/tests/bug35785.php on line %d

http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/026.phpt?view=markup&rev=1.1
Index: php-src/ext/simplexml/tests/026.phpt
+++ php-src/ext/simplexml/tests/026.phpt
--TEST--
SimpleXML: getName()
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php 
$xml =<<<EOF
<people>
  <person>Jane</person>
</people>
EOF;

function traverse_xml($xml, $pad = '')
{
  $name = $xml->getName();
  echo "$pad<$name";
  foreach($xml->attributes() as $attr => $value)
  {
    echo " $attr=\"$value\"";
  }
  echo ">" . trim($xml) . "\n";
  foreach($xml->children() as $node)
  {
    traverse_xml($node, $pad.'  ');
  }
  echo $pad."</$name>\n";
}


$people = simplexml_load_string($xml);
traverse_xml($people);

?>
===DONE===
--EXPECTF--
<people>
  <person>Jane
  </person>
</people>
===DONE===

http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/027.phpt?view=markup&rev=1.1
Index: php-src/ext/simplexml/tests/027.phpt
+++ php-src/ext/simplexml/tests/027.phpt
--TEST--
SimpleXML: Adding an elements
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php 
$xml =<<<EOF
<people></people>
EOF;

function traverse_xml($xml, $pad = '')
{
  $name = $xml->getName();
  echo "$pad<$name";
  foreach($xml->attributes() as $attr => $value)
  {
    echo " $attr=\"$value\"";
  }
  echo ">" . trim($xml) . "\n";
  foreach($xml->children() as $node)
  {
    traverse_xml($node, $pad.'  ');
  }
  echo $pad."</$name>\n";
}


$people = simplexml_load_string($xml);
traverse_xml($people);
$people->person = 'Joe';
$people->person['gender'] = 'male';
traverse_xml($people);
$people->person = 'Jane';
traverse_xml($people);
$people->person['gender'] = 'female';
$people->person[1] = 'Joe';
$people->person[1]['gender'] = 'male';
traverse_xml($people);
$people->person[3] = 'Minni-me';
$people->person[2]['gender'] = 'male';
traverse_xml($people);
$people->person[3]['gender'] = 'error';

?>
===DONE===
--EXPECTF--
<people>
</people>
<people>
  <person gender="male">Joe
  </person>
</people>
<people>
  <person gender="male">Jane
  </person>
</people>
<people>
  <person gender="female">Jane
  </person>
  <person gender="male">Joe
  </person>
</people>

Warning: main(): Cannot add element person number 3 when only 2 such elements 
exist in %sext/simplexml/tests/027.php on line %d
<people>
  <person gender="female">Jane
  </person>
  <person gender="male">Joe
  </person>
  <person gender="male">Minni-me
  </person>
</people>

Fatal error: Objects used as arrays in post/pre increment/decrement must return 
values by reference in %sext/simplexml/tests/027.php on line %d

http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/028.phpt?view=markup&rev=1.1
Index: php-src/ext/simplexml/tests/028.phpt
+++ php-src/ext/simplexml/tests/028.phpt
--TEST--
SimpleXML: Adding an elements without text
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php 
$xml =<<<EOF
<people></people>
EOF;

function traverse_xml($xml, $pad = '')
{
  $name = $xml->getName();
  echo "$pad<$name";
  foreach($xml->attributes() as $attr => $value)
  {
    echo " $attr=\"$value\"";
  }
  echo ">" . trim($xml) . "\n";
  foreach($xml->children() as $node)
  {
    traverse_xml($node, $pad.'  ');
  }
  echo $pad."</$name>\n";
}


$people = simplexml_load_string($xml);
traverse_xml($people);
$people->person['name'] = 'John';
traverse_xml($people);

?>
===DONE===
--EXPECTF--
<people>
</people>
<people>
  <person name="John">
  </person>
</people>
===DONE===

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

Reply via email to