1XML::TreeBuilder(3)   User Contributed Perl Documentation  XML::TreeBuilder(3)
2
3
4

NAME

6       XML::TreeBuilder - Parser that builds a tree of XML::Element objects
7

SYNOPSIS

9         foreach my $file_name (@ARGV) {
10           my $tree = XML::TreeBuilder->new; # empty tree
11           $tree->parse_file($file_name);
12           print "Hey, here's a dump of the parse tree of $file_name:\n";
13           $tree->dump; # a method we inherit from XML::Element
14           print "And here it is, bizarrely rerendered as XML:\n",
15             $tree->as_XML, "\n";
16
17           # Now that we're done with it, we must destroy it.
18           $tree = $tree->delete;
19         }
20

DESCRIPTION

22       This module uses XML::Parser to make XML document trees constructed of
23       XML::Element objects (and XML::Element is a subclass of HTML::Element
24       adapted for XML).  XML::TreeBuilder is meant particularly for people
25       who are used to the HTML::TreeBuilder / HTML::Element interface to
26       document trees, and who don't want to learn some other document
27       interface like XML::Twig or XML::DOM.
28
29       The way to use this class is to:
30
31       1. start a new (empty) XML::TreeBuilder object.
32
33       2. set any of the "store" options you want.
34
35       3. then parse the document from a source by calling
36       "$x->parsefile(...)"  or "$x->parse(...)" (See XML::Parser docs for the
37       options that these two methods take)
38
39       4. do whatever you need to do with the syntax tree, presumably
40       involving traversing it looking for some bit of information in it,
41
42       5. and finally, when you're done with the tree, call $tree->delete to
43       erase the contents of the tree from memory.  This kind of thing usually
44       isn't necessary with most Perl objects, but it's necessary for
45       TreeBuilder objects.  See HTML::Element for a more verbose explanation
46       of why this is the case.
47

METHODS AND ATTRIBUTES

49       XML::TreeBuilder is a subclass of XML::Element, which in turn is a
50       subclass of HTML:Element.  You should read and understand the
51       documentation for those two modules.
52
53       An XML::TreeBuilder object is just a special XML::Element object that
54       allows you to call these additional methods:
55
56       $root = XML::TreeBuilder->new()
57           Construct a new XML::TreeBuilder object.
58
59       $root->parse(...options...)
60           Uses XML::Parser's "parse" method to parse XML from the source(s?)
61           specified by the options.  See XML::Parse
62
63       $root->parsefile(...options...)
64           Uses XML::Parser's "parsefile" method to parse XML from the
65           source(s?)  specified by the options.  See XML::Parse
66
67       $root->parse_file(...options...)
68           Simply an alias for "parsefile".
69
70       $root->store_comments(value)
71           This determines whether TreeBuilder will normally store comments
72           found while parsing content into $root.  Currently, this is off by
73           default.
74
75       $root->store_declarations(value)
76           This determines whether TreeBuilder will normally store markup
77           declarations found while parsing content into $root.  Currently,
78           this is off by default.
79
80       $root->store_pis(value)
81           This determines whether TreeBuilder will normally store processing
82           instructions found while parsing content into $root.  Currently,
83           this is off (false) by default.
84

SEE ALSO

86       XML::Parser, XML::Element, HTML::TreeBuilder, HTML::DOMbo.
87
88       And for alternate XML document interfaces, XML::DOM and XML::Twig.
89
91       Copyright (c) 2000,2004 Sean M. Burke.  All rights reserved.
92
93       This library is free software; you can redistribute it and/or modify it
94       under the same terms as Perl itself.
95
96       This program is distributed in the hope that it will be useful, but
97       without any warranty; without even the implied warranty of
98       merchantability or fitness for a particular purpose.
99

AUTHOR

101       Sean M. Burke, <sburke@cpan.org>
102
103
104
105perl v5.10.1                      2010-11-12               XML::TreeBuilder(3)
Impressum