Advertisement
Guest User

Untitled

a guest
Oct 26th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.03 KB | None | 0 0
  1. use v6;
  2. use lib './';
  3. use Gumbo;
  4.  
  5. my $html = "<html><head class='piko'><title>piko</title><!-- kdlskdsd --></html>";
  6.  
  7. $html = slurp @*ARGS[0] if @*ARGS[0].defined;
  8. my $xml = parse-html($html);
  9.  
  10. print_xml(:xmldoc($xml.root), :tag_only(True));
  11.  
  12. sub     print_xml ($xmldoc, $cpt = 0, $tag_only = False) {
  13.     if $xmldoc ~~ XML::Comment && !$tag_only {
  14.       say "--" x $cpt, '<!-- ', $xmldoc.data;
  15.       return ;
  16.     }
  17.     if $xmldoc ~~ XML::Text && !$tag_only {
  18.       say "--" x $cpt, $xmldoc.text;
  19.       return ;
  20.     }
  21.     say "--" x $cpt, "<" , $xmldoc.name, ' attr : ', $xmldoc.attribs.perl if $xmldoc ~~ XML::Element;
  22.     return if ! $xmldoc.nodes.Bool;
  23.     for $xmldoc.nodes -> $mychild {
  24.        print_xml($mychild, $cpt + 1, $tag_only);
  25.     }
  26.     say "--" x $cpt, "</" , $xmldoc.name if $xmldoc ~~ XML::Element;
  27. }
  28.  
  29.  
  30. root@testperl6:~/piko# perl6 gumbo.pl
  31. <snip output from the module>
  32. Too few positionals passed; expected 1 to 3 arguments but got 0
  33.   in sub print_xml at gumbo.pl:12
  34.   in block <unit> at gumbo.pl:10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement