annotate _test/test_xml.pl @ 3:ae61af01bfa5

sync
author cin
date Wed, 23 Oct 2013 01:13:19 +0400
parents
children 8001dc056331
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
cin
parents:
diff changeset
1 #!/usr/bin/perl
cin
parents:
diff changeset
2 package MyParser;
cin
parents:
diff changeset
3
cin
parents:
diff changeset
4 use IMPL::declare {
cin
parents:
diff changeset
5 base => [
cin
parents:
diff changeset
6 'Yours::Parsers::SaxParser' => undef
cin
parents:
diff changeset
7 ]
cin
parents:
diff changeset
8 };
cin
parents:
diff changeset
9
cin
parents:
diff changeset
10 sub ProcessRootNode {
cin
parents:
diff changeset
11 my ($this,$node) = @_;
cin
parents:
diff changeset
12
cin
parents:
diff changeset
13 my $handler;
cin
parents:
diff changeset
14 my $level = 0;
cin
parents:
diff changeset
15 $handler = sub {
cin
parents:
diff changeset
16 my ($me,$node) = @_;
cin
parents:
diff changeset
17 print ' ' x $level, $node->depth, " ", $node->name,"\n";
cin
parents:
diff changeset
18 $level++;
cin
parents:
diff changeset
19 $me->ReadChildren($handler);
cin
parents:
diff changeset
20 $level--;
cin
parents:
diff changeset
21 };
cin
parents:
diff changeset
22
cin
parents:
diff changeset
23 print "root: \n";
cin
parents:
diff changeset
24 $this->ReadChildren($handler);
cin
parents:
diff changeset
25 }
cin
parents:
diff changeset
26
cin
parents:
diff changeset
27 my $text = '<?xml version="1.0"?>
cin
parents:
diff changeset
28 <root>
cin
parents:
diff changeset
29 <n1></n1>
cin
parents:
diff changeset
30 <n2>
cin
parents:
diff changeset
31 <w1>asd</w1>
cin
parents:
diff changeset
32 </n2>
cin
parents:
diff changeset
33 <n3></n3>
cin
parents:
diff changeset
34 </root>
cin
parents:
diff changeset
35 ';
cin
parents:
diff changeset
36
cin
parents:
diff changeset
37 MyParser->new()->Parse({
cin
parents:
diff changeset
38 string => $text
cin
parents:
diff changeset
39 });
cin
parents:
diff changeset
40