annotate _test/test_xml.pl @ 5:45a84be3ebb1 default tip

added deltainfo (.drpm) packages support
author sergey
date Wed, 23 Oct 2013 16:24:52 +0400
parents 8001dc056331
children
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 {
4
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
5 require => {
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
6 XMLReader => 'XML::LibXML::Reader'
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
7 },
3
cin
parents:
diff changeset
8 base => [
cin
parents:
diff changeset
9 'Yours::Parsers::SaxParser' => undef
cin
parents:
diff changeset
10 ]
cin
parents:
diff changeset
11 };
cin
parents:
diff changeset
12
4
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
13
3
cin
parents:
diff changeset
14 sub ProcessRootNode {
cin
parents:
diff changeset
15 my ($this,$node) = @_;
cin
parents:
diff changeset
16
cin
parents:
diff changeset
17 my $handler;
4
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
18 my $level = 1;
3
cin
parents:
diff changeset
19 $handler = sub {
cin
parents:
diff changeset
20 my ($me,$node) = @_;
cin
parents:
diff changeset
21 print ' ' x $level, $node->depth, " ", $node->name,"\n";
cin
parents:
diff changeset
22 $level++;
cin
parents:
diff changeset
23 $me->ReadChildren($handler);
cin
parents:
diff changeset
24 $level--;
cin
parents:
diff changeset
25 };
cin
parents:
diff changeset
26
cin
parents:
diff changeset
27 print "root: \n";
cin
parents:
diff changeset
28 $this->ReadChildren($handler);
cin
parents:
diff changeset
29 }
cin
parents:
diff changeset
30
cin
parents:
diff changeset
31 my $text = '<?xml version="1.0"?>
4
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
32 <root xmlns:ns="asd">
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
33 <n0/>
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
34 <ns:n1 a="hi"></ns:n1>
3
cin
parents:
diff changeset
35 <n2>
cin
parents:
diff changeset
36 <w1>asd</w1>
cin
parents:
diff changeset
37 </n2>
4
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
38 <n3 />
3
cin
parents:
diff changeset
39 </root>
cin
parents:
diff changeset
40 ';
cin
parents:
diff changeset
41
4
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
42 my $reader = XMLReader->new({
3
cin
parents:
diff changeset
43 string => $text
cin
parents:
diff changeset
44 });
cin
parents:
diff changeset
45
4
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
46 while ($reader->read) {
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
47 print " " x $reader->depth, "[", $reader->nodeType,"] ", $reader->name, "\n"
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
48 }
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
49
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
50 print "\n";
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
51
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
52 MyParser->new()->Parse({
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
53 string => $text
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
54 });
8001dc056331 fixed problems with sax parser
sergey
parents: 3
diff changeset
55