afiskon/p6-xml-parser-tiny/lib/XML/Parser/Tiny

p6-xml-parser-tiny src
} #!/usr/bin/env perl6 use v6; use XML::Parser::Tiny::Grammar; use XML::Parser::Tiny::Actions; class XML::Parser::Tiny; has $!grammar = XML::Parser::Tiny::Grammar; has $!actions = XML::Parser::Tiny::Actions.new; method parse (Str $xml) {
    if my $m = $!grammar.parse($xml, :$!actions) {
        return $m.ast;
    } else {
        die 'Invalid XML';
    }
 
}

NAME

XML::Parser::Tiny is a module for parsing XML documents.

SYNOPSYS

use XML::Parser::Tiny; my $xml = q{<?xml version="1.0" charset="UTF-8" ?>
    <doc>aaa<bbb key='<+>' ><![CDATA[<ccc>]]></bbb>ddd</doc>
 
}; my $parser = XML::Parser::Tiny.new; my $tree = $parser.parse($xml); say $tree.perl; # { # "head" => [ # { # "name" => "xml", # "attr" => { # "version" => "1.0", # "charset" => "UTF-8" # } # } # ], # "body" => { # "name" => "doc", # "attr" => {}, # "data" => [ # "aaa", # { # "name" => "bbb", # "attr" => { # "key" => "<+>", # }, # "data" => [ "<ccc>" ] # }, # "ddd" # ] # } # }

DESCRIPTION

A module for parsing XML documents.

METHODS

(head2) parse(Str $xml)
Converts XML into structure represented in SYNOPSYS section. This method throws an exception in case of errors.

AUTHOR

Alexandr Alexeev, <eax at cpan.org> (L<http://eax.me/>)

COPYRIGHT

Copyright 2012 Alexandr Alexeev This program is free software; you can redistribute it and/or modify it under the same terms as Rakudo Perl 6 itself.

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: