Re: PHP5, Tidy: node and parent node

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Markus Fischer wrote:
I'm trying to figure out the parent of a node in tidy. As it seems to me there's no property/method available for this.

I really want to avoid traversing the whole document and build the relation myself; this is getting pretty slow.

PHP5 currently doesn't feature this method although the tidy library provides this. I've put together a patch if someone else is interested too.

- Markus
? tidy_getParent.diff.txt
Index: php_tidy.h
===================================================================
RCS file: /repository/php-src/ext/tidy/php_tidy.h,v
retrieving revision 1.25
diff -u -r1.25 php_tidy.h
--- php_tidy.h	25 Apr 2005 20:46:16 -0000	1.25
+++ php_tidy.h	15 Jul 2005 09:59:44 -0000
@@ -89,6 +89,7 @@
 TIDY_NODE_METHOD(isJste);
 TIDY_NODE_METHOD(isAsp);
 TIDY_NODE_METHOD(isPhp);
+TIDY_NODE_METHOD(getParent);
 
 ZEND_BEGIN_MODULE_GLOBALS(tidy)
 	char *default_config;
Index: tidy.c
===================================================================
RCS file: /repository/php-src/ext/tidy/tidy.c,v
retrieving revision 1.65
diff -u -r1.65 tidy.c
--- tidy.c	25 Apr 2005 20:46:16 -0000	1.65
+++ tidy.c	15 Jul 2005 09:59:45 -0000
@@ -291,6 +291,7 @@
 	TIDY_NODE_ME(isJste, NULL)
 	TIDY_NODE_ME(isAsp, NULL)
 	TIDY_NODE_ME(isPhp, NULL)
+	TIDY_NODE_ME(getParent, NULL)
 	{NULL, NULL, NULL}
 };
 
@@ -1668,6 +1669,30 @@
 }
 /* }}} */
 
+/* {{{ proto boolean tidyNode::getParent()
+   Returns the parent node if available or NULL */
+TIDY_NODE_METHOD(getParent)
+{
+	TidyNode	parent_node;
+	PHPTidyObj *newobj;
+	TIDY_FETCH_ONLY_OBJECT;
+
+	parent_node = tidyGetParent(obj->node);
+	if(parent_node) {
+		tidy_instanciate(tidy_ce_node, return_value TSRMLS_CC);
+		newobj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC);
+		newobj->node = parent_node;
+		newobj->type = is_node;
+		newobj->ptdoc = obj->ptdoc;
+		newobj->ptdoc->ref_count++;
+		tidy_add_default_properties(newobj, is_node TSRMLS_CC);
+	} else {
+		ZVAL_NULL(return_value);
+	}
+}
+/* }}} */
+
+
 static void _php_tidy_register_nodetypes(INIT_FUNC_ARGS)
 {
 	TIDY_NODE_CONST(ROOT, Root);

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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux