Markup-Tree
view release on metacpan or search on metacpan
parse (DATA)
Just the same as HTML or XML ::Parse's parse method. Pass in markup
data. For HTML you will need to call eof().
Returns: a refrence to the parser
eof ( )
Signals the end of HTML markup. Calling eof on XML data will not
generate an error, it just won't do anything.
Returns: a refrence to the parser
save_as (FILE [, type])
Saves the tree to FILE as type, if specified.
Arguments:
FILE
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.
type
Valid values are 'html' or 'xml'. Will also accept 'xhtml'.
Default is 'html'.
Example: $tree->save_as
('/home/lackluster/public_html/transformed.html.xml', 'xml');
foreach_node (start_CODE [, end_CODE] [, start_from])
Loops through each node in the syntax tree, calling "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:
start_CODE
This CODE ref will be called when a node is encounted and before
its children have been processed. A Markup::TreeNode element
will be passed to your sub.
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
Markup::TreeNode, the method will interpret "end_CODE" as
"start_from".
start_from
Instead of looping over the whole tree, this value can be a
Markup::TreeNode start point. (See "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"; } );
RETURN VALUES MATTER!
Returning a false value will end the iterations and cause the method
to return. Return true to keep processing.
copy_of
Returns a copy, not a reference, of the tree.
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 "HTML::TreeBuilder" or "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.
BUGS || UNFINISHED
"Wide character in print" warnings are abound. I haven't taken the time
to look into this. Something about UNICODE?
The "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.
SEE ALSO
Markup::TreeNode, XML::Parser, HTML::TreeBuilder, LWP::Simple
AUTHOR
BPrudent (Brandon Prudent)
Email: xlacklusterx@hotmail.com
( run in 0.666 second using v1.01-cache-2.11-cpan-71847e10f99 )