This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics

Nobody in particular
sjurnm [...]

(no value)
Broken in:
(no value)
Fixed in:
  • 3.30
  • 3.31
  • 3.32

Subject: Feature Request with patch: cvs-friendly pretty-print option
Date: Wed, 14 Feb 2007 23:21:38 +0200
From: Sjur Moshagen <>
Hello, Twig produces a number of useful output formats, but not exactly what is needed to adhere to the guidelines outlined at http:// navId.4/navSetId._/vtTopicFile.teamworking%7Cscs% 7Cscs_u_writingversioncontrollablexml~html/ - Writing Version Controllable XML. Specifically, the following combination of options isn't available in my version (which is not the completely newest, but according to the changelog, this feature has not yet been added): * attributes, in sorted order, on separate lines from their element * indented output (easier human readability) * wrapped lines All of them are available in one or more of the existing pp formats, but not all three combined. The attached patch adds a new pp option indented_a (_a as in attribute), with alias cvs, which provides this output style. The rationale behind this output style is to reduce the number of irrelevant diffs when xml documents are stored in a version control system like CVS. As with most other output styles, this one is NOT guaranteed to keep the document valid according to the DTD. Use at your own risk:-) The patched version was tested on a small XML document, and seemed to perform as expected, but should probably be tested on larger documents before the change is commited. The patch is made against the following version: # $Id: Twig_pm.slow,v 1.303 2006/05/26 08:07:14 mrodrigu Exp $ It was made and tested on the following system: Mac OS X 10.4.8 This is perl, v5.8.6 built for darwin-thread-multi-2level (with 3 registered patches, see perl -V for more detail) As I don't know how the bug tracker handles e-mail attachements, I also paste in the patch at the end of this e-mail (it is short). Best regards, Sjur 6842c6842 < my ($NSGMLS, $NICE, $INDENTED, $INDENTEDC, $WRAPPED, $RECORD1, $RECORD2)= (1..7); ---
Show quoted text
$RECORD1, $RECORD2)= (1..8); 6850a6851,6855
Show quoted text
> indented_a => $INDENTEDA, # nice, indented, and with
attributes on separate
Show quoted text
> # lines as the nsgmls style, as
well as wrapped
Show quoted text
> # lines - to make the xml friendly
against line-
Show quoted text
> # oriented diffs > cvs => $INDENTEDA, # alias for indented_a
6950c6955 < if( $pretty == $WRAPPED) ---
Show quoted text
> if( ($pretty == $WRAPPED) || ($pretty == $INDENTEDA) )
7111c7116,7123 < $tag .= $pretty==$NSGMLS ? "\n" : ' '; ---
Show quoted text
> $tag .= ( ($pretty==$NSGMLS) || ($pretty==
$INDENTEDA) ) ? "\n" : ' ';
Show quoted text
> > if( $pretty==$INDENTEDA) > { my $indent= $elt->level; > my $prefix=''; > $prefix= $INDENT x $indent; > $tag .= $prefix . ' '; > }
7164c7176 < elsif( ($pretty==$INDENTED) || ($pretty==$INDENTEDC) || ($pretty==$WRAPPED)) ---
Show quoted text
> elsif( ($pretty==$INDENTED) || ($pretty==$INDENTEDA) ||
($pretty==$INDENTEDC) || ( $pretty==$WRAPPED)) 7240c7252 < elsif( ($pretty==$INDENTED) || ($pretty==$WRAPPED) ) ---
Show quoted text
> elsif( ($pretty==$INDENTED) || ($pretty==$INDENTEDA) ||
($pretty==$INDENTEDC) || ( $pretty==$WRAPPED) ) 7411c7423 < if( $pretty== $WRAPPED && !$xml_space_preserve) ---
Show quoted text
> if( ($pretty== $WRAPPED || $pretty== $INDENTEDA) && !

Message body is not shown because sender requested not to inline it.

Hi Sjur, Sorry for the very late response, but RT stopped sending email notifications or a while, and I just saw the ticket. Indeed, your patch looks ok, I have applied it to the current development version at .I had to change it a bit because I restructured that part of the code recently (since 3.29), so you might want to test the new version to see if I got it right. I now have to add tests and docs, which should be quick. Thanks a lot for the patch. __ mirod
OK, The latest version, this morning, seems to format properly (see t/test_3_30.t). Note that if you want to keep the attribute order and they are not already alphabetically sorted, you will need to use the keep_atts_order option (as in the test). Let me know if this works for you. __ mirod

This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with to