Mercurial > pub > Yours
comparison _test/test_xml.pl @ 4:8001dc056331
fixed problems with sax parser
fixed handling of empty repos
added log autoflush
author | sergey |
---|---|
date | Wed, 23 Oct 2013 11:49:16 +0400 |
parents | ae61af01bfa5 |
children |
comparison
equal
deleted
inserted
replaced
3:ae61af01bfa5 | 4:8001dc056331 |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 package MyParser; | 2 package MyParser; |
3 | 3 |
4 use IMPL::declare { | 4 use IMPL::declare { |
5 require => { | |
6 XMLReader => 'XML::LibXML::Reader' | |
7 }, | |
5 base => [ | 8 base => [ |
6 'Yours::Parsers::SaxParser' => undef | 9 'Yours::Parsers::SaxParser' => undef |
7 ] | 10 ] |
8 }; | 11 }; |
9 | 12 |
13 | |
10 sub ProcessRootNode { | 14 sub ProcessRootNode { |
11 my ($this,$node) = @_; | 15 my ($this,$node) = @_; |
12 | 16 |
13 my $handler; | 17 my $handler; |
14 my $level = 0; | 18 my $level = 1; |
15 $handler = sub { | 19 $handler = sub { |
16 my ($me,$node) = @_; | 20 my ($me,$node) = @_; |
17 print ' ' x $level, $node->depth, " ", $node->name,"\n"; | 21 print ' ' x $level, $node->depth, " ", $node->name,"\n"; |
18 $level++; | 22 $level++; |
19 $me->ReadChildren($handler); | 23 $me->ReadChildren($handler); |
23 print "root: \n"; | 27 print "root: \n"; |
24 $this->ReadChildren($handler); | 28 $this->ReadChildren($handler); |
25 } | 29 } |
26 | 30 |
27 my $text = '<?xml version="1.0"?> | 31 my $text = '<?xml version="1.0"?> |
28 <root> | 32 <root xmlns:ns="asd"> |
29 <n1></n1> | 33 <n0/> |
34 <ns:n1 a="hi"></ns:n1> | |
30 <n2> | 35 <n2> |
31 <w1>asd</w1> | 36 <w1>asd</w1> |
32 </n2> | 37 </n2> |
33 <n3></n3> | 38 <n3 /> |
34 </root> | 39 </root> |
35 '; | 40 '; |
36 | 41 |
37 MyParser->new()->Parse({ | 42 my $reader = XMLReader->new({ |
38 string => $text | 43 string => $text |
39 }); | 44 }); |
40 | 45 |
46 while ($reader->read) { | |
47 print " " x $reader->depth, "[", $reader->nodeType,"] ", $reader->name, "\n" | |
48 } | |
49 | |
50 print "\n"; | |
51 | |
52 MyParser->new()->Parse({ | |
53 string => $text | |
54 }); | |
55 |