3
|
1 #!/usr/bin/perl
|
|
2 package MyParser;
|
|
3
|
|
4 use IMPL::declare {
|
|
5 base => [
|
|
6 'Yours::Parsers::SaxParser' => undef
|
|
7 ]
|
|
8 };
|
|
9
|
|
10 sub ProcessRootNode {
|
|
11 my ($this,$node) = @_;
|
|
12
|
|
13 my $handler;
|
|
14 my $level = 0;
|
|
15 $handler = sub {
|
|
16 my ($me,$node) = @_;
|
|
17 print ' ' x $level, $node->depth, " ", $node->name,"\n";
|
|
18 $level++;
|
|
19 $me->ReadChildren($handler);
|
|
20 $level--;
|
|
21 };
|
|
22
|
|
23 print "root: \n";
|
|
24 $this->ReadChildren($handler);
|
|
25 }
|
|
26
|
|
27 my $text = '<?xml version="1.0"?>
|
|
28 <root>
|
|
29 <n1></n1>
|
|
30 <n2>
|
|
31 <w1>asd</w1>
|
|
32 </n2>
|
|
33 <n3></n3>
|
|
34 </root>
|
|
35 ';
|
|
36
|
|
37 MyParser->new()->Parse({
|
|
38 string => $text
|
|
39 });
|
|
40
|