]> granicus.if.org Git - php/commitdiff
add optional name parameter to next()
authorRob Richards <rrichards@php.net>
Thu, 22 Jul 2004 15:50:44 +0000 (15:50 +0000)
committerRob Richards <rrichards@php.net>
Thu, 22 Jul 2004 15:50:44 +0000 (15:50 +0000)
  move to next named sibling skipping subtrees

ext/xmlreader/php_xmlreader.c

index 2c9b5b83551d58228ed9118b30eda303773e558e..11cb6110ca05567903833c39630bd37348565510 100644 (file)
@@ -760,18 +760,40 @@ PHP_METHOD(xmlreader, read)
 }
 /* }}} */
 
-/* {{{ proto boolean read()
+/* {{{ proto boolean next([string localname])
 Moves the position of the current instance to the next node in the stream. */
 PHP_METHOD(xmlreader, next)
 {
        zval *id;
-       int retval;
+       int retval, name_len=0;
        xmlreader_object *intern;
+       char *name = NULL;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) {
+               return;
+       }
 
        id = getThis();
        intern = (xmlreader_object *)zend_object_store_get_object(id TSRMLS_CC);
        if (intern != NULL && intern->ptr != NULL) {
                retval = xmlTextReaderNext(intern->ptr);
+               while (name != NULL && retval == 1) {
+#ifdef PHP_WIN32
+                       /* xmlTextReaderConstLocalName should be used once its added to win def libxml.def file.
+                       Doing so will not require localname to be freed as its not allocated */
+                       xmlChar *localname = xmlTextReaderLocalName(intern->ptr);
+                       if (xmlStrEqual(localname, name)) {
+                               xmlFree(localname);
+                               RETURN_TRUE;
+                       }
+                       xmlFree(localname);
+#else
+                       if (xmlStrEqual(xmlTextReaderConstLocalName(intern->ptr), name)) {
+                               RETURN_TRUE;
+                       }
+#endif
+                       retval = xmlTextReaderNext(intern->ptr); 
+               }
                if (retval == -1) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "An Error Occured while reading");
                        RETURN_FALSE;