Mercurial > pub > Yours
diff _test/test_xml.pl @ 3:ae61af01bfa5
sync
author | cin |
---|---|
date | Wed, 23 Oct 2013 01:13:19 +0400 |
parents | |
children | 8001dc056331 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/_test/test_xml.pl Wed Oct 23 01:13:19 2013 +0400 @@ -0,0 +1,40 @@ +#!/usr/bin/perl +package MyParser; + +use IMPL::declare { + base => [ + 'Yours::Parsers::SaxParser' => undef + ] +}; + +sub ProcessRootNode { + my ($this,$node) = @_; + + my $handler; + my $level = 0; + $handler = sub { + my ($me,$node) = @_; + print ' ' x $level, $node->depth, " ", $node->name,"\n"; + $level++; + $me->ReadChildren($handler); + $level--; + }; + + print "root: \n"; + $this->ReadChildren($handler); +} + +my $text = '<?xml version="1.0"?> +<root> + <n1></n1> + <n2> + <w1>asd</w1> + </n2> + <n3></n3> +</root> +'; + +MyParser->new()->Parse({ + string => $text +}); +