.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Reindent 3pm" .TH Reindent 3pm "2021-01-06" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" XML::Filter::Reindent \- Reformats whitespace for pretty printing XML .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use XML::Handler::Composer; \& use XML::Filter::Reindent; \& \& my $composer = new XML::Handler::Composer (%OPTIONS); \& my $indent = new XML::Filter::Reindent (Handler => $composer, %OPTIONS); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" XML::Filter::Reindent is a sub class of XML::Filter::DetectWS. .PP XML::Filter::Reindent can be used as a PerlSAX filter to reformat an \&\s-1XML\s0 document before sending it to a PerlSAX handler that prints it (like XML::Handler::Composer.) .PP Like XML::Filter::DetectWS, it detects ignorable whitespace and blocks of whitespace characters in certain places. It uses this information and information supplied by the user to determine where whitespace may be modified, deleted or inserted. Based on the indent settings, it then modifies, inserts and deletes characters and ignorable_whitespace events accordingly. .PP This is just a first stab at the implementation. It may be buggy and may change completely! .SH "Constructor Options" .IX Header "Constructor Options" .IP "\(bu" 4 Handler .Sp The PerlSAX handler (or filter) that will receive the PerlSAX events from this filter. .IP "\(bu" 4 Tab (Default: one space) .Sp The number of spaces per indent level for elements etc. in document content. .IP "\(bu" 4 Newline (Default: \*(L"\ex0A\*(R") .Sp The newline to use when re-indenting. The default is the internal newline used by XML::Parser, \s-1XML::DOM\s0 etc., and should be fine when used in combination with XML::Handler::Composer. .ie n .SH "$self\->indent_children ($start_element_event)" .el .SH "\f(CW$self\fP\->indent_children ($start_element_event)" .IX Header "$self->indent_children ($start_element_event)" This method determines whether children of a certain element may be reformatted. The default implementation checks the PreserveWS parameter of the specified start_element event and returns 0 if it is set or \s-1MAYBE\s0 otherwise. The value \s-1MAYBE\s0 (2) indicates that further investigation is needed, e.g. by examining the element contents. A value of 1 means yes, indent the child nodes, no further investigation is needed. .PP \&\s-1NOTE:\s0 the PreserveWS parameter is set by the parent class, XML::Filter::DetectWS, when the element or one of its ancestors has the attribute xml:space=\*(L"preserve\*(R". .PP Override this method to tweak the behavior of this class. .ie n .SH "$self\->indent_element ($start_element_event, $parent_says_indent)" .el .SH "\f(CW$self\fP\->indent_element ($start_element_event, \f(CW$parent_says_indent\fP)" .IX Header "$self->indent_element ($start_element_event, $parent_says_indent)" This method determines whether a certain element may be re-indented. The default implementation returns the value of the \f(CW$parent_says_indent\fR parameter, which was set to the value returned by indent_children for the parent element. In other words, the element will be re-indented if the parent element allows it. .PP Override this method to tweak the behavior of this class. I'm not sure how useful this hook is. Please provide feedback! .SH "Current Implementation" .IX Header "Current Implementation" The current implementation puts all incoming Perl \s-1SAX\s0 events in a queue for further processing. When determining which nodes should be re-indented, it sometimes needs information from previous events, hence the use of the queue. .PP The parameter (Compress => 1) is added to matching start_element and end_element events with no events in between This indicates to an \s-1XML\s0 printer that a compressed notation can be used, e.g . .PP If an element allows reformatting of its contents (xml:space=\*(L"preserve\*(R" was not active and indent_children returned \s-1MAYBE\s0), the element contents will be reformatted unless it only has one child node and that child is a regular text node (characters event.) In that case, the element will be printed as text contents. .PP If you want element nodes with just one text child to be reindented as well, simply override indent_children to return 1 instead of \s-1MAYBE\s0 (2.) .PP This behavior may be changed or extended in the future. .SH "CAVEATS" .IX Header "CAVEATS" This code is highly experimental! It has not been tested well and the \s-1API\s0 may change. .PP The code that detects blocks of whitespace at potential indent positions may need some work. .SH "AUTHOR" .IX Header "AUTHOR" Original Author is Enno Derksen. .PP Send bug reports, hints, tips, suggestions to T.J. Mather at <\fItjmather@tjmather.com\fR>.