Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Jul 20, 2009
1 parent 5e5969e commit 7d614c5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
34 changes: 20 additions & 14 deletions lib/HTML/TreeBuilder/LibXML.pm
Expand Up @@ -94,29 +94,35 @@ __END__
=head1 NAME
HTML::TreeBuilder::LibXML - HTML::TreeBuilder::XPath compatible interface with libxml
HTML::TreeBuilder::LibXML - HTML::TreeBuilder and XPath compatible interface with libxml
=head1 SYNOPSIS
use HTML::TreeBuilder::LibXML;
my $tree = HTML::TreeBuilder::LibXML->new;
$tree->parse($html);
$tree->eof;
# $tree and $node compatible to HTML::Element
my @nodes = $tree->findvalue($xpath);
for my $node (@nodes) {
print $node->tag;
my %attr = $node->all_external_attr;
}
HTML::TreeBuilder::LibXML->replace_original(); # replace HTML::TreeBuilder::XPath->new
=head1 DESCRIPTION
HTML::TreeBuilder is bit slow for some use case.
and, XML::LibXML is very fast!
I want to use it. But, some libraries uses HTML::TreeBuilder.
HTML::TreeBuilder::XPath is libxml based compatible interface to
HTML::TreeBuilder, which could be slow for a large document.
HTML::TreeBuilder::LibXML is drop-in-replacement for HTML::TreeBuilder::XPath.
Currently, this module implements good enough methods for work with Web::Scraper.
=head1 TODO
12:39 miyagawa:> tokuhirom_______: HTML::TreeBuilder::LibXML で->eofがない
12:40 miyagawa:> ほかにもありそうだけど
12:43 miyagawa:> あと look_down と findvalue
12:43 miyagawa:> が Remedie/Plagger でつかわれてる。
This module doesn't implement all of HTML::TreeBuilder and
HTML::Element APIs, but eough methods are defined so modules like
Web::Scraper work.
=head1 BENCHMARK
Expand All @@ -134,13 +140,13 @@ This is a benchmark result by tools/benchmark.pl
Tokuhiro Matsuno E<lt>tokuhirom slkjfd gmail.comE<gt>
Tatsuhiko Miyagawa E<lt>miyagawa@cpan.orgE<gt>
=head1 THANKS TO
woremacx++
http://d.hatena.ne.jp/woremacx/20080202/1201927162
Tatsuhiko Miyagawa
id:dailyflower
=head1 SEE ALSO
Expand Down
39 changes: 32 additions & 7 deletions lib/HTML/TreeBuilder/LibXML/Node.pm
Expand Up @@ -3,13 +3,6 @@ use strict;
use warnings;
use Carp();

=head1 TODO
parent
=cut


sub new {
my ($class, $node) = @_;
Carp::croak 'missing node' unless $node;
Expand Down Expand Up @@ -167,3 +160,35 @@ sub _eof_or_die {
}

1;

__END__
=head1 NAME
HTML::TreeBuilder::LibXML::Node - HTML::Element compatible API for HTML::TreeBuilder::LibXML
=head1 SYNOPSIS
my $value = $node->attr('name');
my $string = $node->string_value;
my $text = $node->as_text;
my $xml = $node->as_XML;
my $html = $node->as_HTML;
my $tag = $node->tag;
my $id = $node->id;
my $clone = $node->clone;
$node->delete;
$node->look_down(@args);
my %attr = $node->all_attr;
my %attr = $node->all_external_attr;
my @names = $node->all_attr_names;
my @names = $node->all_external_attr_names;
# HTML::TreeBuilder::XPath
my @nodes = $node->findnodes($xpath);
my $value = $node->findvalue($xpath);
$node->isTextNode;
my $child = $node->getFirstChild;
=back

0 comments on commit 7d614c5

Please sign in to comment.