XML-Tidy-1.20/0000755000175000017500000000000013130441060011135 5ustar pippipXML-Tidy-1.20/MANIFEST.SKIP0000644000175000017500000000013012732211566013042 0ustar pippip\bCVS\b ^Makefile$ ^MANIFEST\.bak$ ^updt.*$ \.bak$ \.swp$ \..*\.swp$ \b\.xvpics\b \# ~$ XML-Tidy-1.20/Makefile.PL0000644000175000017500000000162213130440734013117 0ustar pippipuse ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'XML::Tidy', # 'VERSION_FROM' => 'lib/XML/Tidy.pm', 'VERSION' => '1.20', # 'ABSTRACT_FROM' => 'lib/XML/Tidy.pm', 'ABSTRACT' => 'tidy indenting of XML documents', 'LICENSE' => 'gpl_3', 'AUTHOR' => [ 'Pip Stuart ' ], 'EXE_FILES' => [ 'bin/xmltidy' ], 'TEST_REQUIRES' => { 'Test' => 0, 'Test::More' => 0, 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0, }, # Module::Name => 1.1, 'PREREQ_PM' => { 'Carp' => 0, 'Math::BaseCnv' => 0, 'XML::XPath' => 0, 'XML::XPath::XMLParser' => 0, }, 'dist' => { 'COMPRESS' => 'gzip', 'SUFFIX' => '.tgz' }, ); XML-Tidy-1.20/ex/0000755000175000017500000000000013130441060011551 5ustar pippipXML-Tidy-1.20/ex/synopsis.pl0000644000175000017500000000050213130133326013775 0ustar pippip#!/usr/bin/perl use strict;use warnings; use utf8;use XML::Tidy; # create new XML::Tidy object by loading: MainFile.xml my $tidy_obj = XML::Tidy->new('filename' => 'MainFile.xml'); # tidy up the indenting $tidy_obj->tidy(); # write out changes back to MainFile.xml $tidy_obj->write(); XML-Tidy-1.20/Changes0000644000175000017500000001065513130440651012444 0ustar pippipCHANGES Revision history for Perl extension XML::Tidy: - 1.20 H79M9hU8 Sun Jul 9 09:43:30:08 -0500 2017 * removed broken Build.PL to resolve . (Thank you, Slaven.) - 1.18 H78M5qm1 Sat Jul 8 05:52:48:01 -0500 2017 * fixed new() to check file or xml to detect standalone in declaration, from (Thanks Alex!) * traced tidy() memory leak from (Thanks Jozef!) which seems to come from every XPath->findnodes() call * aligned synopsis comments * updated write() to use output encoding UTF-8 since that's what almost all XML should rely on (with thanks to RJBS for teaching me much from his great talk at ) * collapsed trailing curly braces on code blocks * added croak for any failed file open attempt - 1.16 G6LM4EST Tue Jun 21 04:14:28:29 -0500 2016 * stopped using my old fragile package generation and manually updated all distribution files (though Dist::Zilla should let me generate much again) * updated license to GPLv3+ * fixed 00pod.t and 01podc.t to eval the Test modules from issue and patch: (Thanks again MichielB.) * replaced all old '&&' with 'and' in POD - 1.14 G6JMERCY Sun Jun 19 14:27:12:34 -0500 2016 * separated old PT from VERSION to fix non-numeric issue: (Thanks to Slaven.) * removed Unicode from POD but added encoding utf8 anyway to pass tests and resolve issues: and (Thanks to Sudhanshu and MichielB.) - 1.12.B55J2qn Thu May 5 19:02:52:49 2011 * made "1.0" float binarize as float again, rather than just "1" int * cleaned up POD and fixed EXPORTED CONSTANTS heads blocking together - 1.10.B52FpLx Mon May 2 15:51:21:59 2011 * added tests for undefined non-standard XML declaration to suppress warnings - 1.8.B2AMvdl Thu Feb 10 22:57:39:47 2011 * aligned .t code * added test for newline before -r to try to resolve: (Thanks, Leandro.) * fixed off-by-one error when new gets a readable (non-newline) filename (that's not "filename" without a pre-'filename' param) to resolve: (Thanks, Simone.) - 1.6.A7RJKwl Tue Jul 27 19:20:58:47 2010 * added head2 POD for EXPORTED CONSTANTS to try to pass t/00podc.t - 1.4.A7QCvHw Mon Jul 26 12:57:17:58 2010 * hacked a little test for non-UTF-8 decl str to resolve FrankGoss' need for ISO-8859-1 decl encoding to persist through tidying * md sure META.yml is being generated correctly for the CPAN * updated license to GPLv3 - 1.2.75BACCB Fri May 11 10:12:12:11 2007 * made "1.0" float binarize as just "1" int * made ints signed and bounds checked * added new('binary' => 'BinFilename.xtb') option - 1.2.54HJnFa Sun Apr 17 19:49:15:36 2005 * fixed tidy() processing instruction stripping problem * added support for binary ints and floats in bcompress() * tightened up binary format and added pod - 1.2.54HDR1G Sun Apr 17 13:27:01:16 2005 * added bcompress() and bexpand() * added compress() and expand() * added toString() - 1.2.4CKBHxt Mon Dec 20 11:17:59:55 2004 * added exporting of XML::XPath::Node (DOM) constants * added node object creation wrappers (like LibXML) - 1.2.4CCJW4G Sun Dec 12 19:32:04:16 2004 * added optional 'xpath_loc' => to prune() - 1.0.4CAJna1 Fri Dec 10 19:49:36:01 2004 * added optional 'filename' => to write() - 1.0.4CAAf5B Fri Dec 10 10:41:05:11 2004 * removed 2nd param from tidy() so that 1st param is just indent string * fixed pod errors - 1.0.4C9JpoP Thu Dec 9 19:51:50:25 2004 * added xplc option to write() * added prune() - 1.0.4C8K1Ah Wed Dec 8 20:01:10:43 2004 * inherited from XPath so that those methods can be called directly * original version (separating Tidy.pm from Merge.pm) XML-Tidy-1.20/META.json0000644000175000017500000000221513130441060012556 0ustar pippip{ "abstract" : "tidy indenting of XML documents", "author" : [ "Pip Stuart " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.1002, CPAN::Meta::Converter version 2.150005", "license" : [ "gpl_3" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "XML-Tidy", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0", "Test" : "0", "Test::More" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Math::BaseCnv" : "0", "XML::XPath" : "0", "XML::XPath::XMLParser" : "0" } } }, "release_status" : "stable", "version" : "1.20", "x_serialization_backend" : "JSON::PP version 2.27300_01" } XML-Tidy-1.20/t/0000755000175000017500000000000013130441060011400 5ustar pippipXML-Tidy-1.20/t/03medium.t0000644000175000017500000000403412731577152013233 0ustar pippipuse Test; BEGIN { plan tests => 15 } use XML::Tidy; my $tobj; ok(1); sub diff { # test for difference between memory Tidy objects my $tidy = shift() || return(0); my $tstd = shift(); return(0) unless(defined($tstd) && $tstd); my($root)= $tidy->findnodes('/'); my $xdat = qq(\n); $xdat .= $_->toString() for($root->getChildNodes()); if($xdat eq $tstd) { return(1); } # 1 == files same else { return(0); } # 0 == files diff } my $tst1 = qq| |; my $tstE = qq| |; my $tstF = qq| |; my $tstG = qq| |; my $tstH = qq| |; $tobj = XML::Tidy->new($tst1) ; ok(defined($tobj )); ok( diff($tobj, $tst1)); ok( $tobj->get_xml(), $tst1 ); $tobj->reload(); ok(defined($tobj )); ok( diff($tobj, $tst1)); ok( $tobj->get_xml(), $tst1 ); ok( diff($tobj, $tstE)); $tobj->strip(); ok(defined($tobj )); ok( diff($tobj, $tstF)); $tobj->tidy(); ok(defined($tobj )); ok( diff($tobj, $tstG)); $tobj->tidy("\t"); ok(defined($tobj )); ok( $tobj->get_xml(), $tstH ); ok( diff($tobj, $tstH)); XML-Tidy-1.20/t/06decl.t0000644000175000017500000000342213130120313012636 0ustar pippipuse Test; BEGIN {plan tests => 15} use XML::Tidy; my $tobj; ok(1); sub diff{ # test for difference between memory Tidy objects my $tidy = shift() || return(0); my $tstd = shift(); return(0) unless(defined($tstd) && $tstd); my $xdat = $tidy->toString(); # changed from 02small.t to test rare non-UTF8 XML declar8ions maybe with standalone if($xdat eq $tstd){ return(1);} # files same else { return(0);}} # files diff eror my $tst0 = qq| |; my $tstA = qq| |; my $tstB = qq| |; my $tstC = qq| |; my $tstD = qq| |; $tobj = XML::Tidy->new($tst0) ; ok(defined($tobj )); ok( diff($tobj, $tst0)); ok( $tobj->get_xml(), $tst0 ); $tobj->reload(); ok(defined($tobj )); ok( diff($tobj, $tst0)); ok( $tobj->get_xml(), $tst0 ); ok( diff($tobj, $tstA)); $tobj->strip(); ok(defined($tobj )); ok( diff($tobj, $tstB)); $tobj->tidy(); $tobj = XML::Tidy->new($tstC) ; ok(defined($tobj )); ok( diff($tobj, $tstC)); $tobj->tidy("\t"); ok(defined($tobj )); ok( $tobj->get_xml(), $tstD ); ok( diff($tobj, $tstD)); XML-Tidy-1.20/t/04large.t0000644000175000017500000004405712731577152013057 0ustar pippipuse Test; BEGIN { plan tests => 15 } use XML::Tidy; my $tobj; ok(1); sub diff { # test for difference between mem XPath obj && disk XML file my $tidy = shift() || return(0); my $tstd = shift(); return(0) unless(defined($tstd) && $tstd); my($root)= $tidy->findnodes('/'); my $xdat = qq(\n); $xdat .= $_->toString() for($root->getChildNodes()); # split root PI's && comments with newlines again $xdat =~ s/\?><\?/\?>\n<\?/g; $xdat =~ s/\?>\n\n RELAX NG schema for XHTML 2.0 Copyright (C)2003-2004 W3C(R) (MIT, ERCIM, Keio), All Rights Reserved. Editor: Masayasu Ishikawa mimasa@w3.org Revision: $Id: xhtml2.rng,v 1.34 2004/07/21 10:33:05 mimasa Exp $ Permission to use, copy, modify and distribute this RELAX NG schema for XHTML 2.0 and its accompanying documentation for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice and this paragraph appear in all copies. The copyright holders make no representation about the suitability of this RELAX NG schema for any purpose. It is provided "as is" without expressed or implied warranty. For details, please refer to the W3C software license at: http://www.w3.org/Consortium/Legal/copyright-software
XHTML 2.0 modules Attribute Collections Module Document Module Structural Module Text Module Hypertext Module List Module Metainformation Module Object Module Scripting Module Style Attribute Module Style Sheet Module Tables Module Support Modules Datatypes Module Events Module Param Module Caption Module
XML Events module
Ruby module
XForms module To-Do: work out integration of XForms
XML Schema instance module
|; my $tstI = q| RELAX NG schema for XHTML 2.0 Copyright (C)2003-2004 W3C(R) (MIT, ERCIM, Keio), All Rights Reserved. Editor: Masayasu Ishikawa mimasa@w3.org Revision: $Id: xhtml2.rng,v 1.34 2004/07/21 10:33:05 mimasa Exp $ Permission to use, copy, modify and distribute this RELAX NG schema for XHTML 2.0 and its accompanying documentation for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice and this paragraph appear in all copies. The copyright holders make no representation about the suitability of this RELAX NG schema for any purpose. It is provided "as is" without expressed or implied warranty. For details, please refer to the W3C software license at: http://www.w3.org/Consortium/Legal/copyright-software
XHTML 2.0 modules Attribute Collections Module Document Module Structural Module Text Module Hypertext Module List Module Metainformation Module Object Module Scripting Module Style Attribute Module Style Sheet Module Tables Module Support Modules Datatypes Module Events Module Param Module Caption Module
XML Events module
Ruby module
XForms module To-Do: work out integration of XForms
XML Schema instance module
|; my $tstJ = q| RELAX NG schema for XHTML 2.0 Copyright (C)2003-2004 W3C(R) (MIT, ERCIM, Keio), All Rights Reserved. Editor: Masayasu Ishikawa mimasa@w3.org Revision: $Id: xhtml2.rng,v 1.34 2004/07/21 10:33:05 mimasa Exp $ Permission to use, copy, modify and distribute this RELAX NG schema for XHTML 2.0 and its accompanying documentation for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice and this paragraph appear in all copies. The copyright holders make no representation about the suitability of this RELAX NG schema for any purpose. It is provided "as is" without expressed or implied warranty. For details, please refer to the W3C software license at: http://www.w3.org/Consortium/Legal/copyright-software
XHTML 2.0 modulesAttribute Collections ModuleDocument ModuleStructural ModuleText ModuleHypertext ModuleList ModuleMetainformation ModuleObject ModuleScripting ModuleStyle Attribute ModuleStyle Sheet ModuleTables ModuleSupport ModulesDatatypes ModuleEvents ModuleParam ModuleCaption Module
XML Events module
Ruby module
XForms moduleTo-Do: work out integration of XForms
XML Schema instance module
|; my $tstK = q| RELAX NG schema for XHTML 2.0 Copyright (C)2003-2004 W3C(R) (MIT, ERCIM, Keio), All Rights Reserved. Editor: Masayasu Ishikawa mimasa@w3.org Revision: $Id: xhtml2.rng,v 1.34 2004/07/21 10:33:05 mimasa Exp $ Permission to use, copy, modify and distribute this RELAX NG schema for XHTML 2.0 and its accompanying documentation for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice and this paragraph appear in all copies. The copyright holders make no representation about the suitability of this RELAX NG schema for any purpose. It is provided "as is" without expressed or implied warranty. For details, please refer to the W3C software license at: http://www.w3.org/Consortium/Legal/copyright-software
XHTML 2.0 modules Attribute Collections Module Document Module Structural Module Text Module Hypertext Module List Module Metainformation Module Object Module Scripting Module Style Attribute Module Style Sheet Module Tables Module Support Modules Datatypes Module Events Module Param Module Caption Module
XML Events module
Ruby module
XForms module To-Do: work out integration of XForms
XML Schema instance module
|; my $tstL = q| RELAX NG schema for XHTML 2.0 Copyright (C)2003-2004 W3C(R) (MIT, ERCIM, Keio), All Rights Reserved. Editor: Masayasu Ishikawa mimasa@w3.org Revision: $Id: xhtml2.rng,v 1.34 2004/07/21 10:33:05 mimasa Exp $ Permission to use, copy, modify and distribute this RELAX NG schema for XHTML 2.0 and its accompanying documentation for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice and this paragraph appear in all copies. The copyright holders make no representation about the suitability of this RELAX NG schema for any purpose. It is provided "as is" without expressed or implied warranty. For details, please refer to the W3C software license at: http://www.w3.org/Consortium/Legal/copyright-software
XHTML 2.0 modules Attribute Collections Module Document Module Structural Module Text Module Hypertext Module List Module Metainformation Module Object Module Scripting Module Style Attribute Module Style Sheet Module Tables Module Support Modules Datatypes Module Events Module Param Module Caption Module
XML Events module
Ruby module
XForms module To-Do: work out integration of XForms
XML Schema instance module
|; $tobj = XML::Tidy->new($tst2) ; ok(defined($tobj )); ok( $tobj->get_xml(), $tst2 ); ok( diff($tobj, $tst2)); ok( $tobj->get_xml(), $tst2 ); $tobj->reload(); ok(defined($tobj )); ok( diff($tobj, $tst2)); ok(defined($tobj )); #k( $tobj->get_xml(), $tstI ); ok( diff($tobj, $tstI)); $tobj->strip(); ok(defined($tobj )); ok( diff($tobj, $tstJ)); $tobj->tidy(); ok(defined($tobj )); ok( diff($tobj, $tstK)); $tobj->tidy("\t"); ok(defined($tobj )); ok( diff($tobj, $tstL)); XML-Tidy-1.20/t/00pod.t0000644000175000017500000000035213130136533012515 0ustar pippipuse Test::More; eval 'use Test::Pod 1.00 tests => 1'; plan skip_all => 'Test::Pod 1.00 required for testing POD' if $@; #my @pdrs = qw(. blib); #all_pod_files_ok(all_pod_files(@pdrs)); pod_file_ok('lib/XML/Tidy.pm','Valid POD file'); XML-Tidy-1.20/t/02small.t0000644000175000017500000000332512731577152013064 0ustar pippipuse Test; BEGIN { plan tests => 15 } use XML::Tidy; my $tobj; ok(1); sub diff { # test for difference between memory Tidy objects my $tidy = shift() || return(0); my $tstd = shift(); return(0) unless(defined($tstd) && $tstd); my($root)= $tidy->findnodes('/'); my $xdat = qq(\n); $xdat .= $_->toString() for($root->getChildNodes()); if($xdat eq $tstd) { return(1); } # 1 == files same else { return(0); } # 0 == files diff } my $tst0 = qq| |; my $tstA = qq| |; my $tstB = qq| |; my $tstC = qq| |; my $tstD = qq| |; $tobj = XML::Tidy->new($tst0) ; ok(defined($tobj )); ok( diff($tobj, $tst0)); ok( $tobj->get_xml(), $tst0 ); $tobj->reload(); ok(defined($tobj )); ok( diff($tobj, $tst0)); ok( $tobj->get_xml(), $tst0 ); ok( diff($tobj, $tstA)); $tobj->strip(); ok(defined($tobj )); ok( diff($tobj, $tstB)); $tobj->tidy(); ok(defined($tobj )); ok( diff($tobj, $tstC)); $tobj->tidy("\t"); ok(defined($tobj )); ok( $tobj->get_xml(), $tstD ); ok( diff($tobj, $tstD)); XML-Tidy-1.20/t/01podc.t0000644000175000017500000000030012732230513012652 0ustar pippipuse Test::More; eval 'use Test::Pod::Coverage'; plan skip_all => 'Test::Pod::Coverage required for testing POD Coverage' if $@; plan tests => 1; pod_coverage_ok('XML::Tidy','POD Covered'); XML-Tidy-1.20/t/05prune.t0000644000175000017500000000516412731577152013113 0ustar pippipuse Test; BEGIN { plan tests => 15 } use XML::Tidy; my $tobj; ok(1); sub diff { # test for difference between memory Tidy objects my $tidy = shift() || return(0); my $tstd = shift(); return(0) unless(defined($tstd) && $tstd); my($root)= $tidy->findnodes('/'); my $xdat = qq(\n); $xdat .= $_->toString() for($root->getChildNodes()); if($xdat eq $tstd) { return(1); } # 1 == files same else { return(0); } # 0 == files diff } my $tst1 = q| |; my $tstM = q| |; my $tstN = q| |; my $tstO = q| |; my $tstP = q| |; my $tstQ = q| |; my $tstR = q| |; my $tstS = q| |; $tobj = XML::Tidy->new($tst1) ; ok(defined($tobj )); ok( diff($tobj, $tst1)); $tobj->prune('/t/u/v'); ok(defined($tobj )); ok( diff($tobj, $tstM)); $tobj->strip(); ok( diff($tobj, $tstN)); $tobj->tidy(); ok( diff($tobj, $tstO)); $tobj = XML::Tidy->new($tst1) ; ok( diff($tobj, $tst1)); $tobj->prune('//v'); $tobj->tidy(); ok( diff($tobj, $tstP)); $tobj = XML::Tidy->new($tst1) ; ok( diff($tobj, $tst1)); $tobj->prune('//v[@name="deux"]'); $tobj->tidy(); ok( diff($tobj, $tstQ)); $tobj = XML::Tidy->new($tst1) ; ok( diff($tobj, $tst1)); $tobj->prune('/t/u[2]'); $tobj->tidy(); ok( diff($tobj, $tstR)); $tobj = XML::Tidy->new($tst1) ; ok( diff($tobj, $tst1)); $tobj->prune('/t/u/*'); $tobj->tidy(); ok( diff($tobj, $tstS)); XML-Tidy-1.20/bin/0000755000175000017500000000000013130441060011705 5ustar pippipXML-Tidy-1.20/bin/xmltidy0000755000175000017500000000172612754376631013361 0ustar pippip#!/usr/bin/perl # 4BJJ9OVI:xmltidy created by Pip Stuart # to tidy up all the element indenting of XML documents. # The accepted parameters to this script are: # filename (presumably an XML file with misaligned elements) # indent_string ('tab' works as an alternate way to specify "\t") # Examples: # two (2) spaces is default # `xmltidy FileName.xml ' ' ` # one (1) space per indent level # `xmltidy FileName.xml ' '` # four (4) spaces per indent level # `xmltidy FileName.xml tab ` # one (1) tab per indent level # This utility is part of the XML::Tidy Perl Module. Please run # `perldoc XML::Tidy` from the command-line for further documentation. # This code is licensed under the GNU General Public License version 3+. use strict;use warnings;use XML::Tidy; my $flnm = shift() || die "USAGE: `$0 FileName.xml ''`\n"; my $nxto = XML::Tidy->new($flnm);$nxto->tidy(shift());$nxto->write(); XML-Tidy-1.20/LICENSE0000644000175000017500000010451312732212013012147 0ustar pippip GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . XML-Tidy-1.20/lib/0000755000175000017500000000000013130441060011703 5ustar pippipXML-Tidy-1.20/lib/XML/0000755000175000017500000000000013130441060012343 5ustar pippipXML-Tidy-1.20/lib/XML/Tidy.pm0000644000175000017500000013556113130440575013637 0ustar pippip# 4C3JHOH1: XML::Tidy.pm by Pip Stuart to tidy indenting of XML documents as parsed XML::XPath objects; package XML::Tidy; use strict;use warnings;use utf8; require Exporter; require XML::XPath; use base qw( XML::XPath Exporter ); use vars qw( $AUTOLOAD @EXPORT ); use XML::XPath::XMLParser; use Carp; use Math::BaseCnv qw(:b64); our $VERSION='1.20';our $d8VS='H79M9hU8'; @EXPORT = qw( UNKNOWN_NODE ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE ELEMENT_DECL_NODE ATT_DEF_NODE XML_DECL_NODE ATTLIST_DECL_NODE NAMESPACE_NODE STANDARD_XML_DECL); sub UNKNOWN_NODE () { 0;} sub ELEMENT_NODE () { 1;} sub ATTRIBUTE_NODE () { 2;} sub TEXT_NODE () { 3;} sub CDATA_SECTION_NODE () { 4;} sub ENTITY_REFERENCE_NODE () { 5;} sub ENTITY_NODE () { 6;} sub PROCESSING_INSTRUCTION_NODE () { 7;} sub COMMENT_NODE () { 8;} sub DOCUMENT_NODE () { 9;} sub DOCUMENT_TYPE_NODE () {10;} sub DOCUMENT_FRAGMENT_NODE () {11;} sub NOTATION_NODE () {12;} sub ELEMENT_DECL_NODE () {13;} # Non core DOM stuff here down sub ATT_DEF_NODE () {14;} sub XML_DECL_NODE () {15;} sub ATTLIST_DECL_NODE () {16;} sub NAMESPACE_NODE () {17;} my $xmld = qq(\n); # Standard XML Declaration sub STANDARD_XML_DECL () {$xmld;} sub new{my $clas = shift();my $xpob = undef;my $dtst=''; # try to also TeST Declar8ions if (lc($_[0]) eq 'binary' && @_ > 1 && length($_[1]) && -r $_[1]){$xpob = bexpand($_[1]);} elsif( $_[0] =~ /\.xtb$/i ){$xpob = bexpand(@_ );} else {$xpob = XML::XPath->new(@_); if ($_[0] eq 'filename' ){shift( @_ );} if ($_[0] !~ /\n/ && -r "$_[0]"){ # special-case loading XML file with non-standard declaration (but doesn't handle inline XML data or IORef yet) open(my $xmlf,'<',$_[0]) or croak "!*EROR*! Cannot open XML file $_[0]! $!\n"; while( <$xmlf>){$dtst.= $_ if($dtst !~ /<\?xml\s+version=.+?\?>/i);} # try to load until decl formed (should almost always be just first line) close( $xmlf) or croak "!*EROR*! Cannot close XML file $_[0]! $!\n";$xmld =~ s/(\?>).*/$1\n/ if(defined($xmld)); }elsif($_[0] eq 'xml' && @_ > 1 && length($_[1]) ){$dtst=$1 if($_[1]=~ /(<\?xml\s+version=.+?\?>\s*?\n)/i); }elsif($_[0] =~ /(<\?xml\s+version=.+?\?>\s*?\n)/i){$dtst=$1; } #else{} # maybe also try to handle ioref or context here by consulting above crE8d XPath obj? $xmld=$dtst if($dtst =~ /^<\?xml\s+version="[^"]+"\s+encoding="[^"]+"(\s+standalone="(yes|no)")?\s*\?>\n$/i); } # if provided XML Declaration above doesn't seem well-formed, then just leave the default as a good standard my $self = bless($xpob, $clas); return($self);} # self just a new XPath obj blessed into Tidy class sub reload{my $self = shift(); # dump XML text && re-parse object to re-index all nodes cleanly if(defined($self)){ my($root)= $self->findnodes('/'); my $data = $xmld; $data.= $_->toString() for($root->getChildNodes()); $self->set_xml($data); my $prsr = XML::XPath::XMLParser->new('xml' => $data); $self->set_context($prsr->parse());}} sub strip{my $self = shift(); # strips out all text nodes from any mixed content if(defined($self)){ my @nodz = $self->findnodes('//*'); for(@nodz){ if ( $_->getNodeType() eq ELEMENT_NODE){my @kidz = $_->getChildNodes(); for my $kidd (@kidz){ if($kidd->getNodeType() eq TEXT_NODE && @kidz > 1 && $kidd->getValue() =~ /^\s*$/){ $kidd->setValue('');}}}} # empty them all out $self->reload();}} # reload all XML as text to re-index nodes sub tidy{ # tidy XML indenting with a specified indent string my $self = shift();my $ndnt = shift() || ' '; $ndnt = "\t" if($ndnt =~ /tab/i ); # allow some indent_type descriptions $ndnt = ' ' if($ndnt =~ /spac/i); if(defined($self)){ $self->strip(); # strips all object's text nodes from mixed content my $dpth = 0; # keep track of element nest depth my $orte = 0 ;my $nrte = 0 ; # old && new root elements my $prre = '';my $pore = ''; # pre && post root element text my($docu)= $self->findnodes('/'); for($docu->getChildNodes()){ if ($_->getNodeType == ELEMENT_NODE){$orte = $_; } elsif(!$orte ){$prre .= $_->toString();} else {$pore .= $_->toString();}} ( $orte)= $self->findnodes('/*') unless($orte); if($orte->getChildNodes()){ # recursively tidy children $nrte = $self->_rectidy($orte, ($dpth + 1), $ndnt);} my $data = $xmld . $prre . $nrte->toString() . $pore; $self->set_xml($data); my $prsr = XML::XPath::XMLParser->new('xml' => $data); $self->set_context($prsr->parse());}} sub _rectidy{ # recursively tidy up indent formatting of elements my $self = shift();my $node = shift(); my $dpth = shift();my $ndnt = shift(); my $tnod = undef; # temporary node which will get nodes surrounding children #$tnod = e($node->getName()); # create element $tnod = XML::XPath::Node::Element->new($node->getName()); # create element for($node->findnodes('@*')){ # copy all attributes $tnod->appendAttribute($_);} for($node->getNamespaces()){ # copy all namespaces $tnod->appendNamespace($_);} my @kidz = $node->getChildNodes();my $lkid; for my $kidd (@kidz){ if($kidd->getNodeType() ne TEXT_NODE && (!$lkid || $lkid->getNodeType() ne TEXT_NODE)){ #$tnod->appendChild(t("\n" . ($ndnt x $dpth))); $tnod->appendChild(XML::XPath::Node::Text->new("\n" . ($ndnt x $dpth)));} if($kidd->getNodeType() eq ELEMENT_NODE){ my @gkdz = $kidd->getChildNodes(); if(@gkdz && ($gkdz[0]->getNodeType() ne TEXT_NODE || (@gkdz > 1 && $gkdz[1]->getNodeType() ne TEXT_NODE))){ $kidd = $self->_rectidy($kidd, ($dpth + 1), $ndnt);}} # recursively tidy $tnod->appendChild($kidd);$lkid = $kidd;} #$tnod->appendChild(t("\n" . ($ndnt x ($dpth - 1)))); $tnod->appendChild(XML::XPath::Node::Text->new("\n" . ($ndnt x ($dpth - 1)))); return($tnod);} sub compress{ # compress an XML::Tidy object into look-up tables my $self = shift();my $flgz = shift(); # options of node types to include my @elut = ();my @alut = (); # element && attribute look-up-tables my %efou = ();my %afou = (); # element && attribute found flags my @vlut = ();my @tlut = (); # attribute value && text my %vfou = ();my %tfou = (); my @nlut = ();my @clut = (); # namespace && comment my %nfou = ();my %cfou = (); my $cstr = "XML::Tidy::compress v$VERSION"; my $ntok = qr/[\(\)\[\]\{\}\/\*\+\?]/; # non-token quoted regex $flgz = 'ea' unless(defined($flgz)); # Default flags: just elemz && attrz $flgz = 'eatvnc' if($flgz eq 'all'); # AttValz && Text seem to work alright but beware of bugs in Comment I haven't been able to squash yet. $self->strip(); # remove non-data text nodes my($root)= $self->findnodes('/'); for($root->findnodes('//comment()')){ my $text = $_->getNodeValue(); if($text =~ s/^XML::Tidy::compress v(\d+)\.(\d+)\.([0-9A-Za-z._]{7})//){ croak "!*EROR*! compress() cannot be performed twice on the same object!\n";}} if($flgz =~ /e[^E]*$/){ # elements for($root->findnodes('//*')){ my $name = $_->getName(); unless(exists($efou{$name})){ push(@elut, $name);$efou{$name} = $#elut;} # 5 below is the index of XML::XPath::Node::Element's node_name field ${$_}->[5] = 'e' . b64($efou{$name});} # $_->setName(... $cstr .= "\ne:@elut" if(@elut);} if($flgz =~ /(a[^A]*|v[^V]*)$/){ # attributes (keys or values) for($root->findnodes('//@*')){ if($flgz =~ /a[^A]*$/){ # attribute keys my $name = $_->getName(); if(exists($efou{$name})){ # reuse element keys matching attributes # 4 is the index of XML::XPath::Node::Attribute's node_key field ${$_}->[4] = 'e' . b64($efou{$name});} # $_->setName(... else{ unless(exists($afou{$name})){ push(@alut, $name);$afou{$name} = $#alut;} ${$_}->[4] = 'a' . b64($afou{$name});}} # $_->setName(... if($flgz =~ /v[^V]*$/){ # attribute values my $wval = $_->getNodeValue(); $wval = '' unless(defined($wval)); for my $valu (split(/\s+/, $wval)){ my $repl = ''; if (exists($efou{$valu})){ # reuse elem keys matching attr valz $repl = 'e' . b64($efou{$valu}); }elsif(exists($afou{$valu})){ # reuse attr keys matching attr valz $repl = 'a' . b64($afou{$valu}); }elsif($valu !~ $ntok){ unless(exists($vfou{$valu})){ push(@vlut, $valu);$vfou{$valu} = $#vlut;} $repl = 'v' . b64($vfou{$valu});} # 5 is the index of XML::XPath::Node::Attribute's node_value field ${$_}->[5] =~ s/(^|\s+)$valu(\s+|$)/$1$repl$2/g if($valu !~ $ntok);}}} $cstr .= "\na:@alut" if(@alut); $cstr .= "\nv:@vlut" if(@vlut);} if($flgz =~ /t[^T]*$/){ # text for($root->findnodes('//text()')){ my $wtxt = $_->getNodeValue(); for my $text (split(/\s+/, $wtxt)){ my $repl = ''; if (exists($efou{$text})){ # reuse elem keys matching text token $repl = 'e' . b64($efou{$text}); }elsif(exists($afou{$text})){ # reuse attr keys matching text token $repl = 'a' . b64($afou{$text}); }elsif(exists($afou{$text})){ # reuse attr valz matching text token $repl = 'v' . b64($vfou{$text}); }elsif($text !~ $ntok){ unless(exists($tfou{$text})){ push(@tlut, $text);$tfou{$text} = $#tlut;} $repl = 't' . b64($tfou{$text});} # 3 is the index of XML::XPath::Node::Text's node_text field ${$_}->[3] =~ s/(^|\s+)$text(\s+|$)/$1$repl$2/g if($text !~ $ntok);}} $cstr .= "\nt:@tlut" if(@tlut);} if($flgz =~ /c[^C]*$/){ # comment for($root->findnodes('//comment()')){ my $wcmt = $_->getNodeValue(); for my $cmnt (split(/\s+/, $wcmt)){ my $repl = ''; if (exists($efou{$cmnt})){ # reuse elem keys matching cmnt token $repl = 'e' . b64($efou{$cmnt}); }elsif(exists($afou{$cmnt})){ # reuse attr keys matching cmnt token $repl = 'a' . b64($afou{$cmnt}); }elsif(exists($afou{$cmnt})){ # reuse attr valz matching cmnt token $repl = 'v' . b64($vfou{$cmnt}); }elsif(exists($tfou{$cmnt})){ # reuse text valz matching cmnt token $repl = 't' . b64($tfou{$cmnt}); }elsif($cmnt !~ $ntok){ unless(exists($cfou{$cmnt})){ push(@clut, $cmnt);$cfou{$cmnt} = $#clut;} $repl = 'c' . b64($cfou{$cmnt});} # 3 is the index of XML::XPath::Node::Comment's node_comment field ${$_}->[3] =~ s/(^|\s+)$cmnt(\s+|$)/$1$repl$2/g if($cmnt !~ $ntok);}} $cstr .= "\nc:@clut" if(@clut);} $root->appendChild($self->c($cstr)); $self->reload();} sub expand{ # uncompress an XML::Tidy object from look-up tables my $self = shift();my $flgz = shift(); # options of node types to include my @elut = ();my @alut = (); # element && attribute look-up-tables my @vlut = ();my @tlut = (); # attribute value && text my @nlut = ();my @clut = (); # namespace && comment my $ntok = qr/[\(\)\[\]\{\}\/\*\+\?]/; # non-token quoted regex my($root)= $self->findnodes('/'); for($root->findnodes('//comment()')){ my $text = $_->getNodeValue(); if($text =~ s/^XML::Tidy::compress v(\d+)\.(\d+)\.([0-9A-Za-z._]{7})//){ # may need to test $1, $2, $3 for versions later while($text =~ s/^\n([eatvnc]):([^\n]+)//){ my $ntyp = $1;my $lutd = $2; if ($ntyp eq 'e'){ push(@elut, split(/\s+/, $lutd)); }elsif($ntyp eq 'a'){ push(@alut, split(/\s+/, $lutd)); }elsif($ntyp eq 't'){ push(@tlut, split(/\s+/, $lutd)); }elsif($ntyp eq 'v'){ push(@vlut, split(/\s+/, $lutd)); }elsif($ntyp eq 'n'){ # push(@nlut, split(/\s+/, $lutd)); }elsif($ntyp eq 'c'){ push(@clut, split(/\s+/, $lutd));}} $root->removeChild($_);}} if(@elut){ for($root->findnodes('//*')){ my $name = $_->getName(); my $coun = $name; if($coun =~ s/^e// && b10($coun) < @elut){ $coun = b10($coun); # 5 below is the index of XML::XPath::Node::Element's node_name field ${$_}->[5] = $elut[$coun];} # $_->setName($elut[$coun]); else{croak "!*EROR*! expand() cannot find look-up element:$name!\n";}}} if(@alut){ for($root->findnodes('//@*')){ my $name = $_->getName(); my $coun = $name; if ($coun =~ s/^e// && b10($coun) < @elut){ $coun = b10($coun); # 4 below is the index of XML::XPath::Node::Attribute's node_key field ${$_}->[4] = $elut[$coun]; # $_->setName($elut[$coun]); }elsif($coun =~ s/^a// && b10($coun) < @alut){ $coun = b10($coun); ${$_}->[4] = $alut[$coun]; # $_->setName($alut[$coun]); }else{croak "!*EROR*! expand() cannot find look-up attribute key:$name!\n";} if(@vlut){ my $wval = $_->getNodeValue(); for my $valu (split(/\s+/, $wval)){ unless($valu =~ $ntok){ $coun = $valu; if ($coun =~ s/^e// && b10($coun) < @elut){ $coun = b10($coun); # 5 is the index of XML::XPath::Node::Attribute's node_value field ${$_}->[5] =~ s/(^|\s+)$valu(\s+|$)/$1$elut[$coun]$2/g; }elsif($coun =~ s/^a// && b10($coun) < @alut){ $coun = b10($coun); ${$_}->[5] =~ s/(^|\s+)$valu(\s+|$)/$1$alut[$coun]$2/g; }elsif($coun =~ s/^v// && b10($coun) < @vlut){ $coun = b10($coun); ${$_}->[5] =~ s/(^|\s+)$valu(\s+|$)/$1$vlut[$coun]$2/g; }else{croak "!*EROR*! expand() cannot find look-up attribute value:$valu!\n";}}}}}} if(@tlut){ for($root->findnodes('//text()')){ my $wtxt = $_->getNodeValue(); for my $text (split(/\s+/, $wtxt)){ unless($text =~ $ntok){ my $coun = $text; if ($coun =~ s/^e// && b10($coun) < @elut){ $coun = b10($coun); # 3 is the index of XML::XPath::Node::Text's node_text field ${$_}->[3] =~ s/(^|\s+)$text(\s+|$)/$1$elut[$coun]$2/g; }elsif($coun =~ s/^a// && b10($coun) < @alut){ $coun = b10($coun); ${$_}->[3] =~ s/(^|\s+)$text(\s+|$)/$1$alut[$coun]$2/g; }elsif($coun =~ s/^t// && b10($coun) < @tlut){ $coun = b10($coun); ${$_}->[3] =~ s/(^|\s+)$text(\s+|$)/$1$tlut[$coun]$2/g; }elsif($coun =~ s/^v// && b10($coun) < @vlut){ $coun = b10($coun); ${$_}->[3] =~ s/(^|\s+)$text(\s+|$)/$1$vlut[$coun]$2/g; }else{croak "!*EROR*! expand() cannot find look-up text token:$text!\n";}}}}} if(@clut){ for($root->findnodes('//comment()')){ my $wcmt = $_->getNodeValue(); for my $cmnt (split(/\s+/, $wcmt)){ unless($cmnt =~ $ntok){ my $coun = $cmnt; if ($coun =~ s/^e// && b10($coun) < @elut){ $coun = b10($coun); # 3 is the index of XML::XPath::Node::Comment's node_comment field ${$_}->[3] =~ s/(^|\s+)$cmnt(\s+|$)/$1$elut[$coun]$2/g; }elsif($coun =~ s/^a// && b10($coun) < @alut){ $coun = b10($coun); ${$_}->[3] =~ s/(^|\s+)$cmnt(\s+|$)/$1$alut[$coun]$2/g; }elsif($coun =~ s/^v// && b10($coun) < @vlut){ $coun = b10($coun); ${$_}->[3] =~ s/(^|\s+)$cmnt(\s+|$)/$1$vlut[$coun]$2/g; }elsif($coun =~ s/^t// && b10($coun) < @tlut){ $coun = b10($coun); ${$_}->[3] =~ s/(^|\s+)$cmnt(\s+|$)/$1$tlut[$coun]$2/g; }elsif($coun =~ s/^c// && b10($coun) < @clut){ $coun = b10($coun); ${$_}->[3] =~ s/(^|\s+)$cmnt(\s+|$)/$1$clut[$coun]$2/g; }else{croak "!*EROR*! expand() cannot find look-up comment token:$cmnt!\n";}}}}} $self->reload(); $self->tidy();} sub _append_node{ # place a node at the end of the proper array for bcompress my $strz = shift();my $flut = shift(); my $intz = shift();my $fltz = shift(); my $ndty = shift();my $node = shift(); my $tokn = '';my $aval = undef; # token key && attribute value strings if ( ${$node}->getNodeType() == ELEMENT_NODE){ $tokn = ${$node}->getName(); }elsif( ${$node}->getNodeType() == ATTRIBUTE_NODE){ $tokn = ${$node}->getName(); # attribute keys $aval = ${$node}->getNodeValue(); # attribute values $aval = '' unless(defined($aval)); }elsif( ${$node}->getNodeType() == NAMESPACE_NODE){ $tokn = ${$node}->toString(); # namespace prefix && expanded }elsif( ${$node}->getNodeType() == PROCESSING_INSTRUCTION_NODE){ $tokn = ${$node}->getTarget(); # PI target $aval = ${$node}->getData(); # PI data $aval = '' unless(defined($aval)); }else{ # text, comment $tokn = ${$node}->getNodeValue();} if(defined($tokn) && length($tokn)){ unless(exists($flut->{$tokn})){ if ($tokn =~ /^([+-]?\d+)$/ && # unsigned 4294967295 -2147483648 <= $tokn && $tokn <= 2147483647){ push(@{$intz}, $tokn); $flut->{$tokn} = 'l' . (scalar(@{$intz}) - 1); }elsif($tokn =~ /^[+-]?\d+\.\d+$/){ # [+-]1.7x10**-308..[+-]1.7x10**308 push(@{$fltz}, $tokn); $flut->{$tokn} = 'd' . (scalar(@{$fltz}) - 1); }else{ push(@{$strz}, $tokn); $flut->{$tokn} = (scalar(@{$strz}) - 1);}}} if(defined($aval) && length($aval)){ unless(exists($flut->{$aval})){ if ($aval =~ /^([+-]?\d+)$/ && # unsigned 4294967295 -2147483648 <= $aval && $aval <= 2147483647){ push(@{$intz}, $aval); $flut->{$aval} = 'l' . (scalar(@{$intz}) - 1); }elsif($aval =~ /^[+-]?\d+\.\d+$/){ # [+-]1.7x10**-308..[+-]1.7x10**308 push(@{$fltz}, $aval); $flut->{$aval} = 'd' . (scalar(@{$fltz}) - 1); }else{ push(@{$strz}, $aval); $flut->{$aval} = (scalar(@{$strz}) - 1);}}} if( defined($tokn)){ if(length($tokn)){ push(@{$ndty}, $flut->{$tokn}, ${$node}->getNodeType()); }else{ push(@{$ndty}, 1 , ${$node}->getNodeType());}} if( defined($aval)){ if(length($aval)){ push(@{$ndty}, $flut->{$aval}); }else{ push(@{$ndty}, 1 );}} if(${$node}->getNodeType() == ELEMENT_NODE){ for(${$node}->getNamespaces()){ _append_node($strz, $flut, $intz, $fltz, $ndty, \$_);} # load namespaces... for(${$node}->getAttributes()){ _append_node($strz, $flut, $intz, $fltz, $ndty, \$_);} # ...attributes && then child elements recursively for(${$node}->getChildNodes()){ _append_node($strz, $flut, $intz, $fltz, $ndty, \$_);} # before adding an element-close tag to the node order push(@{$ndty}, 0);}} sub bcompress{ # compress an XML::Tidy object into a binary representation my $self = shift(); my $dstf = shift() || 'default.xtb'; # destination binary filename my $bstr = "XML::Tidy::bcompress v$VERSION\0"; my @strz = ('', ''); # array of strings my @intz = ( ); # array of ints my @fltz = ( ); # array of floats my @ndty = (); # list of @strz indices && node types my %flut = ('' => 0, '' => 1); # found string lookup-table $self->strip(); # remove non-data text nodes my $bsiz = 1; my $bpak = 'C'; my($root)= $self->findnodes('/'); for($root->getChildNodes()){ _append_node(\@strz, \%flut, \@intz, \@fltz, \@ndty, \$_);} my $nndx = @ndty; while($nndx >= 256){$nndx /= 256.0;$bsiz++ ;} if ($bsiz == 2 ){$bpak = 'S'; } elsif($bsiz > 2 ){$bpak = 'L';$bsiz = 4;} # assume default XML declaration open( DSTF,'>',$dstf) or croak "!*EROR*! Cannot open binary DSTF: $dstf for writing! $!\n"; binmode(DSTF); print DSTF $bstr; shift(@strz);shift(@strz); # element-close && empty-string are implied print DSTF pack("C$bpak", $bsiz, scalar(@strz)); print DSTF "$_\0" for(@strz) ; print DSTF pack( "$bpak", scalar(@intz)); print DSTF pack('l',$_) for(@intz) ; print DSTF pack( "$bpak", scalar(@fltz)); print DSTF pack('d',$_) for(@fltz) ; while(@ndty){ my $indx = shift(@ndty); if(defined($indx) && $indx){ my $type = shift(@ndty); if(defined($type) && $type){ if ($indx =~ s/^d//){ print DSTF pack("$bpak", (scalar(@strz) + scalar(@intz) + $indx + 2)); }elsif($indx =~ s/^l//){ print DSTF pack("$bpak", (scalar(@strz) + $indx + 2)); }else{ print DSTF pack("$bpak", $indx);} print DSTF pack('C', $type); if($type == ATTRIBUTE_NODE || $type == PROCESSING_INSTRUCTION_NODE){ $indx = shift(@ndty); if ($indx =~ s/^d//){ print DSTF pack("$bpak", (scalar(@strz) + scalar(@intz) + $indx + 2)); }elsif($indx =~ s/^l//){ print DSTF pack("$bpak", (scalar(@strz) + $indx + 2)); }else{ print DSTF pack("$bpak", $indx);}}} }else{ print DSTF pack("$bpak", 0);}} close( DSTF);} sub bexpand{ # uncompress a binary file back into an XML::Tidy object my $self = shift(); my $srcf = shift() || 'default.xtb'; # source binary filename my $srcd = undef; my $cstr = undef; my $bstr = "XML::Tidy::bcompress v$VERSION\0"; my $gxml = ''; # generated XML for new object my @strz = ('', ''); # array of strings my @intz = ( ); # array of ints my @fltz = ( ); # array of floats my @ndty = (); # list of @strz indices && node types my @elst = (); # element stack to track tree reconstruction my $bsiz = 1; my $bpak = 'C'; my $rnam = ''; my $coun = 0; if(-r $srcf){ open( SRCF,'<',$srcf) or croak "!*EROR*! Cannot open binary SRCF: $srcf for reading! $!\n"; binmode(SRCF); $srcd = join('',); close( SRCF); $cstr = substr($srcd, 0, length($bstr), ''); $bsiz = unpack('C', substr($srcd, 0, 1, '')); if ($bsiz == 2){$bpak = 'S';} elsif($bsiz > 2){$bpak = 'L';$bsiz = 4;} $coun = unpack("$bpak", substr($srcd, 0, $bsiz, '')); while($coun--){ push(@strz, ''); my $char = unpack('a', substr($srcd, 0, 1, '')); while($char ne "\0"){ $strz[-1] .= $char; $char = unpack('a', substr($srcd, 0, 1, ''));}} $coun = unpack("$bpak", substr($srcd, 0, $bsiz, '')); while($coun--){ push(@intz, unpack('l', substr($srcd, 0, 4, '')));} $coun = unpack("$bpak", substr($srcd, 0, $bsiz, '')); while($coun--){ push(@fltz, unpack('d', substr($srcd, 0, 8, '')));} #$fltz[-1] .= '.0' if($fltz[-1] !~ /\./); # mk floats look like floats? while(length($srcd)){ push(@ndty, unpack("$bpak", substr($srcd, 0, $bsiz, ''))); if($ndty[-1]){ push(@ndty, unpack('C' , substr($srcd, 0, 1, ''))); $rnam = $strz[$ndty[-2]] if(!length($rnam) && $ndty[-1] == ELEMENT_NODE); if($ndty[-1] == ATTRIBUTE_NODE || $ndty[-1] == PROCESSING_INSTRUCTION_NODE){ push(@ndty, unpack("$bpak", substr($srcd, 0, $bsiz, '')));}}} my $opfl = 0; @elst = (); $gxml = $xmld; while(@ndty){ my $indx = shift(@ndty);my $vndx; my $type = ELEMENT_NODE; $type = shift(@ndty) if($indx); if ($type == ELEMENT_NODE){ $gxml .= '>' if($opfl); if($indx == 0){ # close element $gxml .= ''; $opfl = 0; }else{ push(@elst, $strz[$indx]); $gxml .= '<' . $strz[$indx]; $opfl = 1;} }elsif($type == ATTRIBUTE_NODE){ $vndx = shift(@ndty); if($opfl){ $gxml .= ' '; if ($indx >= (scalar(@strz) + scalar(@intz))){ $gxml .= $fltz[($indx - scalar(@strz) - scalar(@intz))]; }elsif($indx >= scalar(@strz) ){ $gxml .= $intz[($indx - scalar(@strz))]; }else { $gxml .= $strz[$indx];} $gxml .= '="'; if ($vndx >= (scalar(@strz) + scalar(@intz))){ $gxml .= $fltz[($vndx - scalar(@strz) - scalar(@intz))]; }elsif($vndx >= scalar(@strz) ){ $gxml .= $intz[($vndx - scalar(@strz))]; }else { $gxml .= $strz[$vndx];} $gxml .= '"';} }elsif($type == TEXT_NODE){ if($opfl) { $gxml .= '>'; $opfl = 0; } if ($indx >= (scalar(@strz) + scalar(@intz))){ $gxml .= $fltz[($indx - scalar(@strz) - scalar(@intz))]; }elsif($indx >= scalar(@strz) ){ $gxml .= $intz[($indx - scalar(@strz))]; }else { $gxml .= $strz[$indx];} }elsif($type == COMMENT_NODE){ if($opfl){$gxml .= '>'; $opfl = 0;} $gxml .= ''; }elsif($type == PROCESSING_INSTRUCTION_NODE){ if($opfl){$gxml .= '>'; $opfl = 0;} $gxml .= '= (scalar(@strz) + scalar(@intz))){ $gxml .= $fltz[($indx - scalar(@strz) - scalar(@intz))]; }elsif($indx >= scalar(@strz) ){ $gxml .= $intz[($indx - scalar(@strz))]; }else { $gxml .= $strz[$indx];} $gxml .= ' '; $vndx = shift(@ndty); if ($vndx >= (scalar(@strz) + scalar(@intz))){ $gxml .= $fltz[($vndx - scalar(@strz) - scalar(@intz))]; }elsif($vndx >= scalar(@strz) ){ $gxml .= $intz[($vndx - scalar(@strz))]; }else { $gxml .= $strz[$vndx];} $gxml .= '?>'; }elsif($type == NAMESPACE_NODE){ $gxml .= ' ' . $strz[$indx] if($opfl);}} my $nslf = XML::Tidy->new('xml' => "$gxml"); # $nslf->tidy(); # don't force a tidy() even if it's most likely desired return($nslf);}} sub prune{ # remove a section of the tree at the xpath location parameter my $self = shift(); my $xplc = shift() || return(); # can't prune root node if(defined($xplc) && $xplc && $xplc =~ /^[-_]?(xplc$|xpath_loc)/){ $xplc = shift() || undef;} if(defined($self) && defined($xplc) && length($xplc) && $xplc ne '/'){ $self->reload(); # update all nodes && internal XPath indexing before find for($self->findnodes($xplc)){ my $prnt = $_->getParentNode(); $prnt->removeChild($_) if(defined($prnt));}}} sub write{ # write out an XML file to disk from a Tidy object my $self = shift(); my $root; my $xplc; my $flnm = shift() || $self->get_filename(); if( defined($flnm) && $flnm){ if($flnm =~ /^[-_]?(xplc$|xpath_loc)/){ $xplc = shift() || undef; $flnm = shift() || $self->get_filename();} if($flnm =~ /^[-_]?(flnm|filename)$/ ){ $flnm = shift() || $self->get_filename();}} unless(defined($xplc) && $xplc){ $xplc = shift() || undef;} if( defined($xplc) && $xplc && $xplc =~ /^[-_]?(xplc$|xpath_loc)/){ $xplc = shift() || undef;} if( defined($self) && defined($flnm)){ if(defined($xplc) && $xplc){ $root = XML::XPath::Node::Element->new(); my($rtnd)= $self->findnodes($xplc); $root->appendChild($rtnd); }else{ ($root)= $self->findnodes('/');} open( FILE,'>:encoding(UTF-8)',$flnm) or croak "!*EROR*! Cannot open FILE: $flnm for writing! $!\n"; print FILE $xmld; print FILE $_->toString() , "\n" for($root->getChildNodes()); close(FILE); }else{ croak("!*EROR*! No filename could be found to write() to!\n");}} sub toString{ # return XML string from a Tidy object my $self = shift(); my $root; my $xplc = shift(); my $xmls = $xmld; if( defined($xplc) && $xplc && $xplc =~ /^[-_]?(xplc$|xpath_loc)/){ $xplc = shift() || undef;} if( defined($self)){ if(defined($xplc) && $xplc){ $root = XML::XPath::Node::Element->new(); my($rtnd)= $self->findnodes($xplc); $root->appendChild($rtnd); }else{ ($root)= $self->findnodes('/'); # every call to this XPath findnodes('/') leaks memory! I think it's not my fault? } if(defined($root)){ $xmls .= $_->toString() . "\n" for($root->getChildNodes());} }else{ croak("!*EROR*! No XML::Tidy could be found for toString()!\n");} $xmls=~ s/\n$//; # strip final newline (maybe should check at load if there was a just newline text-node after root element close to leave it in?) return($xmls);} sub AUTOLOAD{ # methods (created as necessary) no strict 'refs'; my $self = shift(); if($AUTOLOAD =~ /.*::(new|create)?([eactpn])/i){ # createNode Wrappers my $node = lc($2); *{$AUTOLOAD} = sub{ # add called sub to function table my $self = shift(); if ($node eq 'e'){return(XML::XPath::Node::Element ->new(@_));} elsif($node eq 'a'){return(XML::XPath::Node::Attribute->new(@_));} elsif($node eq 'c'){return(XML::XPath::Node::Comment ->new(@_));} elsif($node eq 't'){return(XML::XPath::Node::Text ->new(@_));} elsif($node eq 'p'){return(XML::XPath::Node::PI ->new(@_));} elsif($node eq 'n'){return(XML::XPath::Node::Namespace->new(@_));} }; return($self->$AUTOLOAD(@_)); }else{croak "No such method: $AUTOLOAD\n";}} sub DESTROY{} # do nothing but define in case && to calm test warnings 8; =encoding utf8 =head1 NAME XML::Tidy - tidy indenting of XML documents =head1 VERSION This documentation refers to version 1.20 of XML::Tidy, which was released on Sun Jul 9 09:43:30:08 -0500 2017. =head1 SYNOPSIS #!/usr/bin/perl use strict;use warnings; use utf8;use XML::Tidy; # create new XML::Tidy object by loading: MainFile.xml my $tidy_obj = XML::Tidy->new('filename' => 'MainFile.xml'); # tidy up the indenting $tidy_obj->tidy(); # write out changes back to MainFile.xml $tidy_obj->write(); =head1 DESCRIPTION This module creates XML document objects (with inheritance from L) to tidy mixed-content (i.e., non-data) text node indenting. There are also some other handy member functions to compress and expand your XML document object (into either a compact XML representation or a binary one). =head1 USAGE =head2 new() This is the standard Tidy object constructor. Except for the added 'binary' option, it can take the same parameters as an L object constructor to initialize the XML document object. These can be any one of: 'filename' => 'SomeFile.xml' 'binary' => 'SomeBinaryFile.xtb' 'xml' => $variable_which_holds_a_bunch_of_XML_data 'ioref' => $file_InputOutput_reference 'context' => $existing_node_at_specified_context_to_become_new_obj =head2 reload() The reload() member function causes the latest data contained in a Tidy object to be re-parsed (which re-indexes all nodes). This can be necessary after modifications have been made to nodes which impact the tree node hierarchy because L's find() member preserves state information which can get out-of-sync. reload() is probably rarely useful by itself but it is needed by strip() and prune() so it is exposed as a method in case it comes in handy for other uses. =head2 strip() The strip() member function searches the Tidy object for all mixed-content (i.e., non-data) text nodes and empties them out. This will basically unformat any markup indenting. strip() is used by compress() and tidy() but it is exposed because it is also worthwhile by itself. =head2 tidy() The tidy() member function can take a single optional parameter as the string that should be inserted for each indent level. Some examples: # Tidy up indenting with default two (2) spaces per indent level $tidy_obj->tidy(); # Tidy up indenting with four (4) spaces per indent level $tidy_obj->tidy(' '); # Tidy up indenting with one (1) tab per indent level $tidy_obj->tidy('tab' ); # Tidy up indenting with two (2) tabs per indent level $tidy_obj->tidy("\t\t"); The default behavior is to use two (2) spaces for each indent level. The Tidy object gets all mixed-content (i.e., non-data) text nodes reformatted to appropriate indent levels according to tree nesting depth. NOTE: tidy() disturbs some XML escapes in whatever ways L does. It has been brought to my attention that these modules also strip CDATA tags from XML files / data they operate on. Even though CDATA tags don't seem very common, I would very much like for them to work smoothly too. Hopefully the vast majority of files will work fine and future support for any of the more rare types can be added later. Additionally, please take notice that every call to tidy() (as well as reload, strip, and most other XML::Tidy functions) leak some memory due to their usage of XPath's findnodes command. This issue was described helpfully at L. Thanks to Jozef! =head2 compress() The compress() member function calls strip() on the Tidy object then creates an encoded comment which contains the names of elements and attributes as they occurred in the original document. Their respective element and attribute names are replaced with just the appropriate index throughout the document. compress() can accept a parameter describing which node types to attempt to shrink down as abbreviations. This parameter should be a string of just the first letters of each node type you wish to include as in the following mapping: e = elements a = attribute keys v = attribute values *EXPERIMENTAL* t = text nodes *EXPERIMENTAL* c = comment nodes *EXPERIMENTAL* n = namespace nodes *not-yet-implemented* Attribute values ('v') and text nodes ('t') both seem to work fine with current tokenization. I've still labeled them EXPERIMENTAL because they seem more likely to cause problems than valid element or attribute key names. I have some bugs in the comment node compression which I haven't been able to find yet so that one should be avoided for now. Since these three node types ('vtc') all require tokenization, they are not included in default compression ('ea'). An example call which includes values and text would be: $tidy_obj->compress('eavt'); The original document structure (i.e., node hierarchy) is preserved. compress() significantly reduces the file size of most XML documents for when size matters more than immediate human readability. expand() performs the opposite conversion. =head2 expand() The expand() member function reads any XML::Tidy::compress comments from the Tidy object and uses them to reconstruct the document that was passed to compress(). =head2 bcompress('BinaryOutputFilename.xtb') The bcompress() member function stores a binary representation of any Tidy object. The format consists of: 0) a null-terminated version string 1) a byte specifying how many bytes later indices will be 2) the number of bytes from 1 above to designate the total string count 3) the number of null-terminated strings from 2 above 4) the number of bytes from 1 above to designate the total integer count 5) the number of 4-byte integers from 4 above 6) the number of bytes from 1 above to designate the total float count 7) the number of 8-byte (double-precision) floats from 6 above 8) node index sets until the end of the file Normal node index sets consist of two values. The first is an index (again the number of bytes long comes from 1) into the three lists as if they were all linear. The second is a single-byte integer identifying the node type (using standard DOM node type enumerations). A few special cases exist in node index sets though. If the index is null, it is interpreted as a close-element tag (so no accompanying type value is read). On the other end, when the index is non-zero, the type value is always read. In the event that the type corresponds to an attribute or a processing instruction, the next index is read (without another accompanying type value) in order to complete the data fields required by those node types. NOTE: Please bear in mind that the encoding of binary integers and floats only works properly if the values are not surrounded by spaces or other delimiters and each is contained in its own single node. This is necessary to enable thorough reconstruction of whitespace from the original document. I recommend storing every numerical value as an isolated attribute value or text node without any surrounding whitespace. # Examples which encode all numbers as binary: 31.255 -15.65535 16383.7 -1023.63 # Examples which encode all numbers as strings: 2.0 4.0 -2.0 4.0 The default file extension is .xtb (for XML::Tidy Binary). =head2 bexpand('BinaryInputFilename.xtb') The bexpand() member function reads a binary file which was previously written from bcompress(). bexpand() is an XML::Tidy object constructor like new() so it can be called like: my $xtbo = XML::Tidy->bexpand('BinaryInputFilename.xtb'); =head2 prune() The prune() member function takes an XPath location to remove (along with all attributes and child nodes) from the Tidy object. For example, to remove all comments: $tidy_obj->prune('//comment()'); or to remove the third baz (XPath indexing is 1-based): $tidy_obj->prune('/foo/bar/baz[3]'); Pruning your XML tree is a form of tidying too so it snuck in here. =) =head2 write() The write() member function can take an optional filename parameter to write out any changes to the Tidy object. If no parameters are given, write() overwrites the original XML document file (if a 'filename' parameter was given to the constructor). write() will croak() if no filename can be found to write to. write() can also take a secondary parameter which specifies an XPath location to be written out as the new root element instead of the Tidy object's root. Only the first matching element is written. =head2 toString() The toString() member function is almost identical to write() except that it takes no parameters and simply returns the equivalent XML string as a scalar. It is a little weird because normally only L objects have a toString() member but I figure it makes sense to extend the same syntax to the parent object as well, since it is a useful option. =head1 createNode Wrappers The following are just aliases to Node constructors. They'll work with just the unique portion of the node type as the member function name. =head2 e() or el() or elem() or createElement() wrapper for XML::XPath::Node::Element->new() =head2 a() or at() or attr() or createAttribute() wrapper for XML::XPath::Node::Attribute->new() =head2 c() or cm() or cmnt() or createComment() wrapper for XML::XPath::Node::Comment->new() =head2 t() or tx() or text() or createTextNode() wrapper for XML::XPath::Node::Text->new() =head2 p() or pi() or proc() or createProcessingInstruction() wrapper for XML::XPath::Node::PI->new() =head2 n() or ns() or nspc() or createNamespace() wrapper for XML::XPath::Node::Namespace->new() =head1 EXPORTED CONSTANTS Since they are sometimes needed to compare against, XML::Tidy also exports the same node constants as L (which correspond to DOM values). These include: =head2 UNKNOWN_NODE =head2 ELEMENT_NODE =head2 ATTRIBUTE_NODE =head2 TEXT_NODE =head2 CDATA_SECTION_NODE =head2 ENTITY_REFERENCE_NODE =head2 ENTITY_NODE =head2 PROCESSING_INSTRUCTION_NODE =head2 COMMENT_NODE =head2 DOCUMENT_NODE =head2 DOCUMENT_TYPE_NODE =head2 DOCUMENT_FRAGMENT_NODE =head2 NOTATION_NODE =head2 ELEMENT_DECL_NODE =head2 ATT_DEF_NODE =head2 XML_DECL_NODE =head2 ATTLIST_DECL_NODE =head2 NAMESPACE_NODE XML::Tidy also exports: =head2 STANDARD_XML_DECL which returns a reasonable default XML declaration string (assuming typical "utf-8" encoding). =head1 TODO =over 2 =item - fix reload() from messing up Unicode escaped &XYZ; components like Copyright © and Registered ® (probably needs pre and post processing) =item - write many better UTF-8 tests =item - support namespaces =item - handle CDATA =back =head1 CHANGES Revision history for Perl extension XML::Tidy: =over 2 =item - 1.20 H79M9hU8 Sun Jul 9 09:43:30:08 -0500 2017 * removed broken Build.PL to resolve L. (Thank you, Slaven.) =item - 1.18 H78M5qm1 Sat Jul 8 05:52:48:01 -0500 2017 * fixed new() to check file or xml to detect standalone in declaration, from L (Thanks Alex!) * traced tidy() memory leak from L (Thanks Jozef!) which seems to come from every XPath->findnodes() call * aligned synopsis comments * updated write() to use output encoding UTF-8 since that's what almost all XML should rely on (with thanks to RJBS for teaching me much from his great talk at L) * collapsed trailing curly braces on code blocks * added croak for any failed file open attempt =item - 1.16 G6LM4EST Tue Jun 21 04:14:28:29 -0500 2016 * stopped using my old fragile package generation and manually updated all distribution files (though L should let me generate much again) * updated license to GPLv3+ * fixed 00pod.t and 01podc.t to eval the Test modules from issue and patch: L (Thanks again MichielB.) * replaced all old '&&' with 'and' in POD =item - 1.14 G6JMERCY Sun Jun 19 14:27:12:34 -0500 2016 * separated old PT from VERSION to fix non-numeric issue: L (Thanks to Slaven.) * removed Unicode from POD but added encoding utf8 anyway to pass tests and resolve issues: L and L (Thanks to Sudhanshu and MichielB.) =item - 1.12.B55J2qn Thu May 5 19:02:52:49 2011 * made "1.0" float binarize as float again, rather than just "1" int * cleaned up POD and fixed EXPORTED CONSTANTS heads blocking together =item - 1.10.B52FpLx Mon May 2 15:51:21:59 2011 * added tests for undefined non-standard XML declaration to suppress warnings =item - 1.8.B2AMvdl Thu Feb 10 22:57:39:47 2011 * aligned .t code * added test for newline before -r to try to resolve: L (Thanks, Leandro.) * fixed off-by-one error when new gets a readable (non-newline) filename (that's not "filename" without a pre-'filename' param) to resolve: L (Thanks, Simone.) =item - 1.6.A7RJKwl Tue Jul 27 19:20:58:47 2010 * added head2 POD for EXPORTED CONSTANTS to try to pass t/00podc.t =item - 1.4.A7QCvHw Mon Jul 26 12:57:17:58 2010 * hacked a little test for non-UTF-8 decl str to resolve FrankGoss' need for ISO-8859-1 decl encoding to persist through tidying * md sure META.yml is being generated correctly for the CPAN * updated license to GPLv3 =item - 1.2.75BACCB Fri May 11 10:12:12:11 2007 * made "1.0" float binarize as just "1" int * made ints signed and bounds checked * added new('binary' => 'BinFilename.xtb') option =item - 1.2.54HJnFa Sun Apr 17 19:49:15:36 2005 * fixed tidy() processing instruction stripping problem * added support for binary ints and floats in bcompress() * tightened up binary format and added pod =item - 1.2.54HDR1G Sun Apr 17 13:27:01:16 2005 * added bcompress() and bexpand() * added compress() and expand() * added toString() =item - 1.2.4CKBHxt Mon Dec 20 11:17:59:55 2004 * added exporting of XML::XPath::Node (DOM) constants * added node object creation wrappers (like LibXML) =item - 1.2.4CCJW4G Sun Dec 12 19:32:04:16 2004 * added optional 'xpath_loc' => to prune() =item - 1.0.4CAJna1 Fri Dec 10 19:49:36:01 2004 * added optional 'filename' => to write() =item - 1.0.4CAAf5B Fri Dec 10 10:41:05:11 2004 * removed 2nd param from tidy() so that 1st param is just indent string * fixed pod errors =item - 1.0.4C9JpoP Thu Dec 9 19:51:50:25 2004 * added xplc option to write() * added prune() =item - 1.0.4C8K1Ah Wed Dec 8 20:01:10:43 2004 * inherited from XPath so that those methods can be called directly * original version (separating Tidy.pm from Merge.pm) =back =head1 INSTALL From the command shell, please run: `perl -MCPAN -e "install XML::Tidy"` or uncompress the package and run the standard: `perl Makefile.PL; make; make test; make install` =head1 FILES XML::Tidy requires: L to allow errors to croak() from calling sub L to use XPath statements to query and update XML L to parse XML documents into XPath objects L to handle base-64 indexing for compress() and expand() =head1 BUGS Please report any bugs or feature requests to bug-XML-Tidy at RT.CPAN.Org, or through the web interface at L. I will be notified, and then you can be updated of progress on your bug as I address fixes. =head1 SUPPORT You can find documentation for this module (after it is installed) with the perldoc command. `perldoc XML::Tidy` You can also look for information at: RT: CPAN's Request Tracker HTTPS://RT.CPAN.Org/NoAuth/Bugs.html?Dist=XML-Tidy AnnoCPAN: Annotated CPAN documentation HTTP://AnnoCPAN.Org/dist/XML-Tidy CPAN Ratings HTTPS://CPANRatings.Perl.Org/d/XML-Tidy Search CPAN HTTP://Search.CPAN.Org/dist/XML-Tidy =head1 LICENSE Most source code should be Free! Code I have lawful authority over is and shall be! Copyright: (c) 2004-2017, Pip Stuart. Copyleft : This software is licensed under the GNU General Public License (version 3 or later). Please consult L for important information about your freedom. This is Free Software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. See L for further information. =head1 AUTHOR Pip Stuart =cut XML-Tidy-1.20/META.yml0000644000175000017500000000125513130441060012411 0ustar pippip--- abstract: 'tidy indenting of XML documents' author: - 'Pip Stuart ' build_requires: ExtUtils::MakeMaker: '0' Test: '0' Test::More: '0' Test::Pod: '0' Test::Pod::Coverage: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.1002, CPAN::Meta::Converter version 2.150005' license: gpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: XML-Tidy no_index: directory: - t - inc requires: Carp: '0' Math::BaseCnv: '0' XML::XPath: '0' XML::XPath::XMLParser: '0' version: '1.20' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' XML-Tidy-1.20/MANIFEST0000644000175000017500000000031113130424014012261 0ustar pippiplib/XML/Tidy.pm LICENSE MANIFEST MANIFEST.SKIP META.json META.yml README Changes Makefile.PL t/00pod.t t/01podc.t t/02small.t t/03medium.t t/04large.t t/05prune.t t/06decl.t ex/synopsis.pl bin/xmltidy XML-Tidy-1.20/README0000644000175000017500000004265013130440651012031 0ustar pippipNAME XML::Tidy - tidy indenting of XML documents VERSION This documentation refers to version 1.20 of XML::Tidy, which was released on Sun Jul 9 09:43:30:08 -0500 2017. SYNOPSIS #!/usr/bin/perl use strict;use warnings; use utf8;use XML::Tidy; # create new XML::Tidy object by loading: MainFile.xml my $tidy_obj = XML::Tidy->new('filename' => 'MainFile.xml'); # tidy up the indenting $tidy_obj->tidy(); # write out changes back to MainFile.xml $tidy_obj->write(); DESCRIPTION This module creates XML document objects (with inheritance from XML::XPath) to tidy mixed-content (i.e., non-data) text node indenting. There are also some other handy member functions to compress and expand your XML document object (into either a compact XML representation or a binary one). USAGE new() This is the standard Tidy object constructor. Except for the added 'binary' option, it can take the same parameters as an XML::XPath object constructor to initialize the XML document object. These can be any one of: 'filename' => 'SomeFile.xml' 'binary' => 'SomeBinaryFile.xtb' 'xml' => $variable_which_holds_a_bunch_of_XML_data 'ioref' => $file_InputOutput_reference 'context' => $existing_node_at_specified_context_to_become_new_obj reload() The reload() member function causes the latest data contained in a Tidy object to be re-parsed (which re-indexes all nodes). This can be necessary after modifications have been made to nodes which impact the tree node hierarchy because XML::XPath's find() member preserves state information which can get out-of-sync. reload() is probably rarely useful by itself but it is needed by strip() and prune() so it is exposed as a method in case it comes in handy for other uses. strip() The strip() member function searches the Tidy object for all mixed-content (i.e., non-data) text nodes and empties them out. This will basically unformat any markup indenting. strip() is used by compress() and tidy() but it is exposed because it is also worthwhile by itself. tidy() The tidy() member function can take a single optional parameter as the string that should be inserted for each indent level. Some examples: # Tidy up indenting with default two (2) spaces per indent level $tidy_obj->tidy(); # Tidy up indenting with four (4) spaces per indent level $tidy_obj->tidy(' '); # Tidy up indenting with one (1) tab per indent level $tidy_obj->tidy('tab' ); # Tidy up indenting with two (2) tabs per indent level $tidy_obj->tidy("\t\t"); The default behavior is to use two (2) spaces for each indent level. The Tidy object gets all mixed-content (i.e., non-data) text nodes reformatted to appropriate indent levels according to tree nesting depth. NOTE: tidy() disturbs some XML escapes in whatever ways XML::XPath does. It has been brought to my attention that these modules also strip CDATA tags from XML files / data they operate on. Even though CDATA tags don't seem very common, I would very much like for them to work smoothly too. Hopefully the vast majority of files will work fine and future support for any of the more rare types can be added later. Additionally, please take notice that every call to tidy() (as well as reload, strip, and most other XML::Tidy functions) leak some memory due to their usage of XPath's findnodes command. This issue was described helpfully at . Thanks to Jozef! compress() The compress() member function calls strip() on the Tidy object then creates an encoded comment which contains the names of elements and attributes as they occurred in the original document. Their respective element and attribute names are replaced with just the appropriate index throughout the document. compress() can accept a parameter describing which node types to attempt to shrink down as abbreviations. This parameter should be a string of just the first letters of each node type you wish to include as in the following mapping: e = elements a = attribute keys v = attribute values *EXPERIMENTAL* t = text nodes *EXPERIMENTAL* c = comment nodes *EXPERIMENTAL* n = namespace nodes *not-yet-implemented* Attribute values ('v') and text nodes ('t') both seem to work fine with current tokenization. I've still labeled them EXPERIMENTAL because they seem more likely to cause problems than valid element or attribute key names. I have some bugs in the comment node compression which I haven't been able to find yet so that one should be avoided for now. Since these three node types ('vtc') all require tokenization, they are not included in default compression ('ea'). An example call which includes values and text would be: $tidy_obj->compress('eavt'); The original document structure (i.e., node hierarchy) is preserved. compress() significantly reduces the file size of most XML documents for when size matters more than immediate human readability. expand() performs the opposite conversion. expand() The expand() member function reads any XML::Tidy::compress comments from the Tidy object and uses them to reconstruct the document that was passed to compress(). bcompress('BinaryOutputFilename.xtb') The bcompress() member function stores a binary representation of any Tidy object. The format consists of: 0) a null-terminated version string 1) a byte specifying how many bytes later indices will be 2) the number of bytes from 1 above to designate the total string count 3) the number of null-terminated strings from 2 above 4) the number of bytes from 1 above to designate the total integer count 5) the number of 4-byte integers from 4 above 6) the number of bytes from 1 above to designate the total float count 7) the number of 8-byte (double-precision) floats from 6 above 8) node index sets until the end of the file Normal node index sets consist of two values. The first is an index (again the number of bytes long comes from 1) into the three lists as if they were all linear. The second is a single-byte integer identifying the node type (using standard DOM node type enumerations). A few special cases exist in node index sets though. If the index is null, it is interpreted as a close-element tag (so no accompanying type value is read). On the other end, when the index is non-zero, the type value is always read. In the event that the type corresponds to an attribute or a processing instruction, the next index is read (without another accompanying type value) in order to complete the data fields required by those node types. NOTE: Please bear in mind that the encoding of binary integers and floats only works properly if the values are not surrounded by spaces or other delimiters and each is contained in its own single node. This is necessary to enable thorough reconstruction of whitespace from the original document. I recommend storing every numerical value as an isolated attribute value or text node without any surrounding whitespace. # Examples which encode all numbers as binary: 31.255 -15.65535 16383.7 -1023.63 # Examples which encode all numbers as strings: 2.0 4.0 -2.0 4.0 The default file extension is .xtb (for XML::Tidy Binary). bexpand('BinaryInputFilename.xtb') The bexpand() member function reads a binary file which was previously written from bcompress(). bexpand() is an XML::Tidy object constructor like new() so it can be called like: my $xtbo = XML::Tidy->bexpand('BinaryInputFilename.xtb'); prune() The prune() member function takes an XPath location to remove (along with all attributes and child nodes) from the Tidy object. For example, to remove all comments: $tidy_obj->prune('//comment()'); or to remove the third baz (XPath indexing is 1-based): $tidy_obj->prune('/foo/bar/baz[3]'); Pruning your XML tree is a form of tidying too so it snuck in here. =) write() The write() member function can take an optional filename parameter to write out any changes to the Tidy object. If no parameters are given, write() overwrites the original XML document file (if a 'filename' parameter was given to the constructor). write() will croak() if no filename can be found to write to. write() can also take a secondary parameter which specifies an XPath location to be written out as the new root element instead of the Tidy object's root. Only the first matching element is written. toString() The toString() member function is almost identical to write() except that it takes no parameters and simply returns the equivalent XML string as a scalar. It is a little weird because normally only XML::XPath::Node objects have a toString() member but I figure it makes sense to extend the same syntax to the parent object as well, since it is a useful option. createNode Wrappers The following are just aliases to Node constructors. They'll work with just the unique portion of the node type as the member function name. e() or el() or elem() or createElement() wrapper for XML::XPath::Node::Element->new() a() or at() or attr() or createAttribute() wrapper for XML::XPath::Node::Attribute->new() c() or cm() or cmnt() or createComment() wrapper for XML::XPath::Node::Comment->new() t() or tx() or text() or createTextNode() wrapper for XML::XPath::Node::Text->new() p() or pi() or proc() or createProcessingInstruction() wrapper for XML::XPath::Node::PI->new() n() or ns() or nspc() or createNamespace() wrapper for XML::XPath::Node::Namespace->new() EXPORTED CONSTANTS Since they are sometimes needed to compare against, XML::Tidy also exports the same node constants as XML::XPath::Node (which correspond to DOM values). These include: UNKNOWN_NODE ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE ELEMENT_DECL_NODE ATT_DEF_NODE XML_DECL_NODE ATTLIST_DECL_NODE NAMESPACE_NODE XML::Tidy also exports: STANDARD_XML_DECL which returns a reasonable default XML declaration string (assuming typical "utf-8" encoding). TODO - fix reload() from messing up Unicode escaped &XYZ; components like Copyright © and Registered ® (probably needs pre and post processing) - write many better UTF-8 tests - support namespaces - handle CDATA CHANGES Revision history for Perl extension XML::Tidy: - 1.20 H79M9hU8 Sun Jul 9 09:43:30:08 -0500 2017 * removed broken Build.PL to resolve . (Thank you, Slaven.) - 1.18 H78M5qm1 Sat Jul 8 05:52:48:01 -0500 2017 * fixed new() to check file or xml to detect standalone in declaration, from (Thanks Alex!) * traced tidy() memory leak from (Thanks Jozef!) which seems to come from every XPath->findnodes() call * aligned synopsis comments * updated write() to use output encoding UTF-8 since that's what almost all XML should rely on (with thanks to RJBS for teaching me much from his great talk at ) * collapsed trailing curly braces on code blocks * added croak for any failed file open attempt - 1.16 G6LM4EST Tue Jun 21 04:14:28:29 -0500 2016 * stopped using my old fragile package generation and manually updated all distribution files (though Dist::Zilla should let me generate much again) * updated license to GPLv3+ * fixed 00pod.t and 01podc.t to eval the Test modules from issue and patch: (Thanks again MichielB.) * replaced all old '&&' with 'and' in POD - 1.14 G6JMERCY Sun Jun 19 14:27:12:34 -0500 2016 * separated old PT from VERSION to fix non-numeric issue: (Thanks to Slaven.) * removed Unicode from POD but added encoding utf8 anyway to pass tests and resolve issues: and (Thanks to Sudhanshu and MichielB.) - 1.12.B55J2qn Thu May 5 19:02:52:49 2011 * made "1.0" float binarize as float again, rather than just "1" int * cleaned up POD and fixed EXPORTED CONSTANTS heads blocking together - 1.10.B52FpLx Mon May 2 15:51:21:59 2011 * added tests for undefined non-standard XML declaration to suppress warnings - 1.8.B2AMvdl Thu Feb 10 22:57:39:47 2011 * aligned .t code * added test for newline before -r to try to resolve: (Thanks, Leandro.) * fixed off-by-one error when new gets a readable (non-newline) filename (that's not "filename" without a pre-'filename' param) to resolve: (Thanks, Simone.) - 1.6.A7RJKwl Tue Jul 27 19:20:58:47 2010 * added head2 POD for EXPORTED CONSTANTS to try to pass t/00podc.t - 1.4.A7QCvHw Mon Jul 26 12:57:17:58 2010 * hacked a little test for non-UTF-8 decl str to resolve FrankGoss' need for ISO-8859-1 decl encoding to persist through tidying * md sure META.yml is being generated correctly for the CPAN * updated license to GPLv3 - 1.2.75BACCB Fri May 11 10:12:12:11 2007 * made "1.0" float binarize as just "1" int * made ints signed and bounds checked * added new('binary' => 'BinFilename.xtb') option - 1.2.54HJnFa Sun Apr 17 19:49:15:36 2005 * fixed tidy() processing instruction stripping problem * added support for binary ints and floats in bcompress() * tightened up binary format and added pod - 1.2.54HDR1G Sun Apr 17 13:27:01:16 2005 * added bcompress() and bexpand() * added compress() and expand() * added toString() - 1.2.4CKBHxt Mon Dec 20 11:17:59:55 2004 * added exporting of XML::XPath::Node (DOM) constants * added node object creation wrappers (like LibXML) - 1.2.4CCJW4G Sun Dec 12 19:32:04:16 2004 * added optional 'xpath_loc' => to prune() - 1.0.4CAJna1 Fri Dec 10 19:49:36:01 2004 * added optional 'filename' => to write() - 1.0.4CAAf5B Fri Dec 10 10:41:05:11 2004 * removed 2nd param from tidy() so that 1st param is just indent string * fixed pod errors - 1.0.4C9JpoP Thu Dec 9 19:51:50:25 2004 * added xplc option to write() * added prune() - 1.0.4C8K1Ah Wed Dec 8 20:01:10:43 2004 * inherited from XPath so that those methods can be called directly * original version (separating Tidy.pm from Merge.pm) INSTALL From the command shell, please run: `perl -MCPAN -e "install XML::Tidy"` or uncompress the package and run the standard: `perl Makefile.PL; make; make test; make install` FILES XML::Tidy requires: Carp to allow errors to croak() from calling sub XML::XPath to use XPath statements to query and update XML XML::XPath::XMLParser to parse XML documents into XPath objects Math::BaseCnv to handle base-64 indexing for compress() and expand() BUGS Please report any bugs or feature requests to bug-XML-Tidy at RT.CPAN.Org, or through the web interface at . I will be notified, and then you can be updated of progress on your bug as I address fixes. SUPPORT You can find documentation for this module (after it is installed) with the perldoc command. `perldoc XML::Tidy` You can also look for information at: RT: CPAN's Request Tracker HTTPS://RT.CPAN.Org/NoAuth/Bugs.html?Dist=XML-Tidy AnnoCPAN: Annotated CPAN documentation HTTP://AnnoCPAN.Org/dist/XML-Tidy CPAN Ratings HTTPS://CPANRatings.Perl.Org/d/XML-Tidy Search CPAN HTTP://Search.CPAN.Org/dist/XML-Tidy LICENSE Most source code should be Free! Code I have lawful authority over is and shall be! Copyright: (c) 2004-2017, Pip Stuart. Copyleft : This software is licensed under the GNU General Public License (version 3 or later). Please consult for important information about your freedom. This is Free Software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. See for further information. AUTHOR Pip Stuart