1XML::Handler::XMLWriterU(s3e)r Contributed Perl DocumentaXtMiLo:n:Handler::XMLWriter(3)
2
3
4

NAME

6       XML::Handler::XMLWriter - a PerlSAX handler for writing readable XML
7

SYNOPSIS

9        use XML::Parser::PerlSAX;
10        use XML::Handler::XMLWriter;
11
12        $my_handler = XML::Handler::XMLWriter->new( I<OPTIONS> );
13
14        XML::Parser::PerlSAX->new->parse(Source => { SystemId => 'REC-xml-19980210.xml' },
15                                         Handler => $my_handler);
16

DESCRIPTION

18       "XML::Handler::XMLWriter" is a PerlSAX handler for writing readable XML
19       (in contrast to Canonical XML, for example).  XML::Handler::XMLWriter
20       can be used with a parser to reformat XML, with XML::DOM or XML::Grove
21       to write out XML, or with other PerlSAX modules that generate events.
22
23       "XML::Handler::XMLWriter" is intended to be used with PerlSAX event
24       generators and does not perform any checking itself (for example,
25       matching start and end element events).  If you want to generate XML
26       directly from your Perl code, use the XML::Writer module.  XML::Writer
27       has an easy to use interface and performs many checks to make sure that
28       the XML you generate is well-formed.
29
30       "XML::Handler::XMLWriter" is a subclass of "XML::Handler::Subs".
31       "XML::Handler::XMLWriter" can be further subclassed to alter it's
32       behavior or to add element-specific handling.  In the subclass, each
33       time an element starts, a method by that name prefixed with `s_' is
34       called with the element to be processed.  Each time an element ends, a
35       method with that name prefixed with `e_' is called.  Any special
36       characters in the element name are replaced by underscores.  If there
37       isn't a start or end method for an element, the default action is to
38       write the start or end tag.  Start and end methods can use the
39       `"print_start_element()"' and `"print_end_element()"' methods to print
40       start or end tags.  Subclasses can call the `"print()"' method to write
41       additional output.
42
43       Subclassing XML::Handler::XMLWriter in this way is similar to
44       XML::Parser's Stream style.
45
46       XML::Handler::Subs maintains a stack of element names,
47       `"$self-"{Names}', and a stack of element nodes, `"$self-"{Nodes}>'
48       that can be used by subclasses.  The current element is pushed on the
49       stacks before calling an element-name start method and popped off the
50       stacks after calling the element-name end method.
51
52       See XML::Handler::Subs for additional methods.
53
54       In addition to the standard PerlSAX handler methods (see PerlSAX for
55       descriptions), XML::Handler::XMLWriter supports the following methods:
56
57       new( OPTIONS )
58           Creates and returns a new instance of XML::Handler::XMLWriter with
59           the given OPTIONS.  Options may be changed at any time by modifying
60           them directly in the hash returned.  OPTIONS can be a list of key,
61           value pairs or a hash.  The following OPTIONS are supported:
62
63           Output
64               An IO::Handle or one of it's subclasses (such as IO::File), if
65               this parameter is not present and the AsString option is not
66               used, the module will write to standard output.
67
68           AsString
69               Return the generated XML as a string from the `"parse()"'
70               method of the PerlSAX event generator.
71
72           Newlines
73               A true or false value; if this parameter is present and its
74               value is true, then the module will insert an extra newline
75               before the closing delimiter of start, end, and empty tags to
76               guarantee that the document does not end up as a single, long
77               line.  If the paramter is not present, the module will not
78               insert the newlines.
79
80           IsSGML
81               A true or false value; if this parameter is present and its
82               value is true, then the module will generate SGML rather than
83               XML.
84
85       print_start_element($element)
86           Print a start tag for `$element'.  This is the default action for
87           the PerlSAX `"start_element()"' handler, but subclasses may use
88           this if they define a start method for an element.
89
90       print_end_element($element)
91           Prints an end tag for `$element'.  This is the default action for
92           the PerlSAX `"end_element()"' handler, but subclasses may use this
93           if they define a start method for an element.
94
95       print($output)
96           Write `$output' to Output and/or append it to the string to be
97           returned.  Subclasses may use this to write additional output.
98

TODO

100       ·   An Elements option that provides finer control over newlines than
101           the Newlines option, where you can choose before and after newline
102           for element start and end tags.  Inspired by the Python XMLWriter.
103
104       ·   Support Doctype and XML declarations.
105

AUTHOR

107       Ken MacLeod, ken@bitsko.slc.ut.us This module is partially derived from
108       XML::Writer by David Megginson.
109

SEE ALSO

111       perl(1), PerlSAX.pod(3)
112
113
114
115perl v5.26.3                      2003-10-21        XML::Handler::XMLWriter(3)
Impressum