Markup-Tree
view release on metacpan or search on metacpan
lib/Markup/Tree.pm view on Meta::CPAN
This is the filename or handle to write the information in. If this
argument is textual, the method will try to guess, based on the
file extension, the second argument if not present.
=item type
Valid values are 'html' or 'xml'. Will also accept 'xhtml'.
Default is 'html'.
=back
Example:
$tree->save_as ('/home/lackluster/public_html/transformed.html.xml', 'xml');
=item foreach_node (start_CODE [, end_CODE] [, start_from])
Loops through each node in the syntax tree, calling C<start_CODE>
and, if present, end_CODE. This method makes looping through the tree really
quite simple and lends itself well to saving files to your own format.
Arguments:
=over 4
=item start_CODE
This CODE ref will be called when a node is encounted and before its children
have been processed. A L<Markup::TreeNode> element will be passed to your sub.
=item end_CODE
If this parameter is present, then the CODE ref will be called after a node is
encountered and after its children have been processed. If end_CODE is not
a CODE ref, but instead a L<Markup::TreeNode>, the method will interpret
C<end_CODE> as C<start_from>.
=item start_from
Instead of looping over the whole tree, this value can be a L<Markup::TreeNode>
start point. (See L</BUGS> section)
Example:
$tree->foreach_node(
sub {
my $node = shift();
indent($node->{'level'});
print $node->{'tagname'}."\n";
},
sub {
my $node = shift();
indent($node->{'level'});
print $node->{'tagname'}."\n";
}
);
=back
B<RETURN VALUES MATTER!>
Returning a false value will end the iterations and cause the method to return.
Return true to keep processing.
=item copy_of
Returns a copy, not a reference, of the tree.
=back
=head1 CAVEATS
This module isn't really the best for people who don't often use markup. It
requires quite a few modules (I actually feed bad about the module requirements),
and C<HTML::TreeBuilder> or C<XML::Parser> is probably a better choice for most things you want to
do. On the upside, if you already have these modules, it is a comparativly easy
way to use markup.
=head1 BUGS || UNFINISHED
"Wide character in print" warnings are abound. I haven't taken the time to look into this.
Something about UNICODE?
The C<foreach_node> method doesn't behave properly when passed the start_from parameter.
That's what I thought, at least. The behaviour may work for you in your situation. Just
know that it may change in the future unless anyone requests otherwise.
Please inform me of other bugs.
=head1 SEE ALSO
L<Markup::TreeNode>, L<XML::Parser>, L<HTML::TreeBuilder>, L<LWP::Simple>
=head1 AUTHOR
BPrudent (Brandon Prudent)
Email: xlacklusterx@hotmail.com
( run in 2.317 seconds using v1.01-cache-2.11-cpan-71847e10f99 )