Debian Codegraph @

README

raw
1 NAME
2 XML::Handler::Trees - PerlSAX handlers for building tree structures
3
4 SYNOPSIS
5 use XML::Handler::Trees;
6 use XML::Parser::PerlSAX;
7
8 my $p=XML::Parser::PerlSAX->new();
9 my $h=XML::Handler::Tree->new();
10 my $tree=$p->parse(Handler=>$h,Source=>{SystemId=>'file.xml'});
11
12 my $p=XML::Parser::PerlSAX->new();
13 my $h=XML::Handler::EasyTree->new(Noempty=>1);
14 my $easytree=$p->parse(Handler=>$h,Source=>{SystemId=>'file.xml'});
15
16 my $p=XML::Parser::PerlSAX->new();
17 my $h=XML::Handler::TreeBuilder->new();
18 $h->store_pis(1);
19 my $tree=$p->parse(Handler=>$h,Source=>{SystemId=>'file.xml'});
20
21 DESCRIPTION
22 XML::Handler::Trees provides three PerlSAX handler classes for building
23 tree structures. XML::Handler::Tree builds the same type of tree as the
24 "Tree" style in XML::Parser. XML::Handler::EasyTree builds the same type
25 of tree as the "EasyTree" style added to XML::Parser by
26 XML::Parser::EasyTree. XML::Handler::TreeBuilder builds the same type of
27 tree as Sean M. Burke's XML::TreeBuilder. These classes make it possible
28 to construct these tree structures from sources other than XML::Parser.
29
30 All three handlers can be driven by either PerlSAX 1 or PerlSAX 2
31 drivers. In all cases, the end_document() method returns a reference to
32 the constructed tree, which normally becomes the return value of the
33 PerlSAX driver.
34
35 CLASS XML::Handler::Tree
36 This handler builds the same type of tree structure as the "Tree" style
37 in XML::Parser. Some modules such as Dan Brian's XML::SimpleObject work
38 with this type of tree. See the documentation for XML::Parser for
39 details.
40
41 METHODS
42
43 $handler = XML::Handler::Tree->new()
44 Creates a handler object.
45
46 CLASS XML::Handler::EasyTree
47 This handler builds a lightweight tree structure representing the XML
48 document. This structure is, at least in this author's opinion, easier
49 to work with than the "standard" style of tree. It is the same type of
50 structure as built by XML::Parser when using XML::Parser::EasyTree, or
51 by the get_simple_tree method in XML::Records.
52
53 The tree is returned as a reference to an array of tree nodes, each of
54 which is a hash reference. All nodes have a 'type' key whose value is
55 the type of the node: 'e' for element nodes, 't' for text nodes, and 'p'
56 for processing instruction nodes. All nodes also have a 'content' key
57 whose value is a reference to an array holding the element's child nodes
58 for element nodes, the string value for text nodes, and the data value
59 for processing instruction nodes. Element nodes also have an 'attrib'
60 key whose value is a reference to a hash of attribute names and values.
61 Processing instructions also have a 'target' key whose value is the PI's
62 target.
63
64 EasyTree nodes are ordinary Perl hashes and are not objects. Contiguous
65 runs of text are always returned in a single node.
66
67 The reason the parser returns an array reference rather than the root
68 element's node is that an XML document can legally contain processing
69 instructions outside the root element (the xml-stylesheet PI is commonly
70 used this way).
71
72 If namespace information is available (only possible with PerlSAX 2),
73 element and attribute names will be prefixed with their (possibly empty)
74 namespace URI enclosed in curly brackets, and namespace prefixes will be
75 stripped from names.
76
77 METHODS
78
79 $handler = XML::Handler::EasyTree->new([options])
80 Creates a handler object. Options can be provided hash-style:
81
82 Noempty
83 If this is set to a true value, text nodes consisting entirely
84 of whitespace will not be stored in the tree. The default is
85 false.
86
87 Latin
88 If this is set to a true value, characters with Unicode values
89 in the Latin-1 range (160-255) will be stored in the tree as
90 Latin-1 rather than UTF-8. The default is false.
91
92 CLASS XML::Handler::TreeBuilder
93 This handler builds XML document trees constructed of XML::Element
94 objects (XML::Element is a subclass of HTML::Element adapted for XML).
95 To use it, XML::TreeBuilder and its prerequisite HTML::Tree need to be
96 installed. See the documentation for those modules for information on
97 how to work with these tree structures.
98
99 METHODS
100
101 $handler = XML::Handler::TreeBuilder->new()
102 Creates a handler which builds a tree rooted in an XML::Element.
103
104 $root->store_comments(value)
105 This determines whether comments will be stored in the tree (not all
106 SAX drivers generate comment events). Currently, this is off by
107 default.
108
109 $root->store_declarations(value)
110 This determines whether markup declarations will be stored in the
111 tree. Currently, this is off by default. The present implementation
112 does not store markup declarations in any case; this method is
113 provided for future use.
114
115 $root->store_pis(value)
116 This determines whether processing instructions will be stored in
117 the tree. Currently, this is off (false) by default.
118
119 AUTHOR
120 Eric Bohlman ([email protected])
121
122 Copyright (c) 2001 Eric Bohlman. All rights reserved. This program is
123 free software; you can redistribute it and/or modify it under the same
124 terms as Perl itself.
125
126 SEE ALSO
127 L<perl>
128 L<XML::Parser>
129 L<XML::SimpleObject>
130 L<XML::Parser::EasyTree>
131 L<XML::TreeBuilder>
132 L<XML::Element>
133 L<HTML::Element>
134 L<PerlSAX>
135