source: main/trunk/release-kits/shared/linux/XML-Parser/64-bit/perl-5.24/XML/Parser/Style/Tree.pm@ 31805

Last change on this file since 31805 was 31805, checked in by ak19, 7 years ago

Committing the perl 5.24 that Dr Bainbridge successfully built on Ubuntu 16.06 against (a locally compiled, non-system) perl 5.24 perl. It is a byproduct of compiling up a gs3-svn on the Ubuntu 16.04 with the perl 5.24 in the PATH. This perl-5.24 folder was copied from the gs3-svn's gs2build/perllib/cpan folder. It's being committed into the release-kits area as other versions before have been, as it's needed for release-kits, to generate binaries that will work with perl 5.24. However, the version we generated only has Expat.so, not le Expat.bs. Not sure if that's still necessary, and if so, how it should be generated. See http://www.cryst.bbk.ac.uk/CCSG/programming/perl/PerlDoc/lib/ExtUtils/Mkbootstrap.html for ideas, if the bs extension stands for bootstrap as it seems to.

File size: 2.1 KB
Line 
1# $Id: Tree.pm,v 1.2 2003-07-31 07:54:51 matt Exp $
2
3package XML::Parser::Style::Tree;
4$XML::Parser::Built_In_Styles{Tree} = 1;
5
6sub Init {
7 my $expat = shift;
8 $expat->{Lists} = [];
9 $expat->{Curlist} = $expat->{Tree} = [];
10}
11
12sub Start {
13 my $expat = shift;
14 my $tag = shift;
15 my $newlist = [ { @_ } ];
16 push @{ $expat->{Lists} }, $expat->{Curlist};
17 push @{ $expat->{Curlist} }, $tag => $newlist;
18 $expat->{Curlist} = $newlist;
19}
20
21sub End {
22 my $expat = shift;
23 my $tag = shift;
24 $expat->{Curlist} = pop @{ $expat->{Lists} };
25}
26
27sub Char {
28 my $expat = shift;
29 my $text = shift;
30 my $clist = $expat->{Curlist};
31 my $pos = $#$clist;
32
33 if ($pos > 0 and $clist->[$pos - 1] eq '0') {
34 $clist->[$pos] .= $text;
35 } else {
36 push @$clist, 0 => $text;
37 }
38}
39
40sub Final {
41 my $expat = shift;
42 delete $expat->{Curlist};
43 delete $expat->{Lists};
44 $expat->{Tree};
45}
46
471;
48__END__
49
50=head1 NAME
51
52XML::Parser::Style::Tree
53
54=head1 SYNOPSIS
55
56 use XML::Parser;
57 my $p = XML::Parser->new(Style => 'Tree');
58 my $tree = $p->parsefile('foo.xml');
59
60=head1 DESCRIPTION
61
62This module implements XML::Parser's Tree style parser.
63
64When parsing a document, C<parse()> will return a parse tree for the
65document. Each node in the tree
66takes the form of a tag, content pair. Text nodes are represented with
67a pseudo-tag of "0" and the string that is their content. For elements,
68the content is an array reference. The first item in the array is a
69(possibly empty) hash reference containing attributes. The remainder of
70the array is a sequence of tag-content pairs representing the content
71of the element.
72
73So for example the result of parsing:
74
75 <foo><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo>
76
77would be:
78 Tag Content
79 ==================================================================
80 [foo, [{}, head, [{id => "a"}, 0, "Hello ", em, [{}, 0, "there"]],
81 bar, [ {}, 0, "Howdy", ref, [{}]],
82 0, "do"
83 ]
84 ]
85
86The root document "foo", has 3 children: a "head" element, a "bar"
87element and the text "do". After the empty attribute hash, these are
88represented in it's contents by 3 tag-content pairs.
89
90=cut
Note: See TracBrowser for help on using the repository browser.