function dump_tree(tidy_node $node, $indent = 0) { /* Put something there if the node name is empty */ $nodename = trim(strtoupper($node->name)); $nodename = empty($nodename) ? "[EMPTY]" : $nodename; /* Generate the Node, and a pretty name for it */ do_leaf(" + {$nodename} (" . node_type($node->type) . ")\n", $indent); /* Check to see if this node is a text node. Text nodes are generated by start/end tags and contain the text in between. i.e. <B>foo</B> will create a text node with $node->value equal to 'foo' */ if ($node->type == TIDY_NODETYPE_TEXT) { do_leaf(" |\n", $indent); do_leaf(" +---- Value: '{$node->value}'\n", $indent); } if (count($node->attribute)) { do_leaf(" |\n", $indent); do_leaf(" +---- Attributes\n", $indent); foreach ($node->attribute as $name => $value) { @do_leaf(" +-- {$name}\n", $indent); do_leaf(" | +-- Value: {$value}\n", $indent); } } /* Recurse along the children to generate the remaining nodes */ if ($node->hasChildren()) { foreach ($node->child as $child) { dump_tree($child, $indent + 3); } } }
function dump_nodes(tidy_node $node, &$urls = NULL) { $urls = is_array($urls) ? $urls : array(); if (isset($node->id)) { if ($node->id == TIDY_TAG_A) { $urls[] = $node->attribute['href']; } } if ($node->hasChildren()) { foreach ($node->child as $c) { dump_nodes($c, $urls); } } return $urls; }