Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v6;
- use lib './';
- use Gumbo;
- my $html = "<html><head class='piko'><title>piko</title><!-- kdlskdsd --></html>";
- $html = slurp @*ARGS[0] if @*ARGS[0].defined;
- my $xml = parse-html($html);
- print_xml(:xmldoc($xml.root), :tag_only(True));
- sub print_xml ($xmldoc, $cpt = 0, $tag_only = False) {
- if $xmldoc ~~ XML::Comment && !$tag_only {
- say "--" x $cpt, '<!-- ', $xmldoc.data;
- return ;
- }
- if $xmldoc ~~ XML::Text && !$tag_only {
- say "--" x $cpt, $xmldoc.text;
- return ;
- }
- say "--" x $cpt, "<" , $xmldoc.name, ' attr : ', $xmldoc.attribs.perl if $xmldoc ~~ XML::Element;
- return if ! $xmldoc.nodes.Bool;
- for $xmldoc.nodes -> $mychild {
- print_xml($mychild, $cpt + 1, $tag_only);
- }
- say "--" x $cpt, "</" , $xmldoc.name if $xmldoc ~~ XML::Element;
- }
- root@testperl6:~/piko# perl6 gumbo.pl
- <snip output from the module>
- Too few positionals passed; expected 1 to 3 arguments but got 0
- in sub print_xml at gumbo.pl:12
- in block <unit> at gumbo.pl:10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement