XMLSORT(1p) User Contributed Perl Documentation XMLSORT(1p)NAME
xmlsort - sorts 'records' in XML files
SYNOPSIS
xmlsort -r=<recordname> [ <other options> ] [ <filename> ]
Options:
-r <name> name of the elements to be sorted
-k <keys> child nodes to be used as sort keys
-i ignore case when sorting
-s normalise whitespace when comparing sort keys
-t <dir> buffer records to named directory rather than in memory
-m <bytes> set memory chunk size for disk buffering
-h help - display the full documentation
Example:
xmlsort -r 'person' -k 'lastname;firstname' -i -s in.xml >out.xml
DESCRIPTION
This script takes an XML document either on STDIN or from a named file and writes a sorted version of the file to STDOUT. The "-r" option
should be used to identify 'records' in the document - the bits you want sorted. Elements before and after the records will be unaffected
by the sort.
OPTIONS
Here is a brief summary of the command line options (and the XML::Filter::Sort options which they correspond to). For more details see
XML::Filter::Sort.
-r <recordname> (Record)
The name of the elements to be sorted. This can be a simple element name like 'person' or a pathname like 'employees/person' (only
person elements contained directly within an employees element).
-k <keys> (Keys)
Semicolon separated list of elements (or attributes) within a record which should be used as sort keys. Each key can optionally be
followed by 'alpha' or 'num' to indicate alphanumeric of numeric sorting and 'asc' or 'desc' for ascending or descending order (eg: -k
'lastname;firstname;age,n,d').
-i (IgnoreCase)
This option makes sort comparisons case insensitive.
-s (NormaliseKeySpace)
By default all whitespace in the sort key elements is considered significant. Specifying -s will case leading and trailing whitespace
to be stripped and internal whitespace runs to be collapsed to a single space.
-t <directory> (TempDir)
When sorting large documents, it may be prudent to use disk buffering rather than memory buffering. This option allows you to specify
where temporary files should be written.
-m <bytes> (MaxMem)
If you use the -t option to enable disk buffering, records will be collected in memory in 'chunks' of up to about 10 megabytes before
being sorted and spooled to temporary files. This option allows you to specify a larger chunk size. A suffix of K or M indicates
kilobytes or megabytes respectively.
SEE ALSO
This script uses the following modules:
XML::SAX::ParserFactory
XML::Filter::Sort
XML::SAX::Writer
AUTHOR
Grant McLean <grantm@cpan.org>
COPYRIGHT
Copyright (c) 2002 Grant McLean. All rights reserved. This program is free software; you can redistribute it and/or modify it under the
same terms as Perl itself.
perl v5.12.4 2002-06-14 XMLSORT(1p)
Check Out this Related Man Page
XML::SAX::Machines(3pm) User Contributed Perl Documentation XML::SAX::Machines(3pm)NAME
XML::SAX::Machines - manage collections of SAX processors
SYNOPSIS
use XML::SAX::Machines qw( :all );
my $m = Pipeline(
"My::Filter1", ## My::Filter1 autoloaded in Pipeline()
"My::Filter2", ## My::Filter2 " " "
*STDOUT, ## XML::SAX::Writer also loaded
);
$m->parse_uri( $uri ); ## A parser is autoloaded via
## XML::SAX::ParserFactory if
## My::Filter1 isn't a parser.
## To import only individual machines:
use XML::SAX::Machines qw( Manifold );
## Here's a multi-pass machine that reads one document, runs
## it through 5 filtering channels (one channel at a time) and
## reassembles it in to a single document.
my $m = Manifold(
"My::TableOfContentsExtractor",
"My::AbstractExtractor",
"My::BodyFitler",
"My::EndNotesFilter",
"My::IndexFilter",
);
$m->parse_string( $doc );
DESCRIPTION
SAX machines are a way to gather and manage SAX processors without going nuts. Or at least without going completely nuts. Individual
machines can also be like SAX processors; they don't need to parse or write anything:
my $w = XML::SAX::Writer->new( Output => *STDOUT );
my $m = Pipeline( "My::Filter1", "My::Filter2", { Handler => $w } );
my $p = XML::SAX::ParserFactory->new( handler => $p );
More documentation to come; see XML::SAX::Pipeline, XML::SAX::Manifold, and XML::SAX::Machine for now.
Here are the machines this module knows about:
ByRecord Record oriented processing of documents.
L<XML::SAX::ByRecord>
Machine Generic "directed graph of SAX processors" machines.
L<XML::SAX::Machine>
Manifold Multipass document processing
L<XML::SAX::Manifold>
Pipeline A linear sequence of SAX processors
L<XML::SAX::Pipeline>
Tap An insertable pass through that examines the
events without altering them using SAX processors.
L<XML::SAX::Tap>
Config file
As mentioned in "LIMITATIONS", you might occasionally need to edit the config file to tell XML::SAX::Machine how to handle a particular SAX
processor (SAX processors use a wide variety of API conventions).
The config file is a the Perl module XML::SAX::Machines::SiteConfig, which contains a Perl data structure like:
package XML::SAX::Machines::SiteConfig;
$ProcessorClassOptions = {
"XML::Filter::Tee" => {
ConstructWithHashedOptions => 1,
},
};
So far $Processors is the only available configuration structure. It contains a list of SAX processors with known special needs.
Also, so far the only special need is the ConstructWithHashes option which tells XML::SAX::Machine to construct such classes like:
XML::Filter::Tee->new(
{ Handler => $h }
);
instead of
XML::Filter::Tee->new( Handler => $h );
WARNING If you modify anything, apply your changes in a new file created from XML::SAX::Machines::SiteConfig.pm. On Debian systems, this
should be placed in /etc/perl so that it is not overwritten during upgrade. Do not alter XML::SAX::Machines::ConfigDefaults.pm or you will
lose your changes when you upgrade.
TODO: Allow per-app and per-machine overrides of options. When needed.
AUTHORS
Barrie Slaymaker
LICENCE
Copyright 2002-2009 by Barrie Slaymaker.
This software is free. It is licensed under the same terms as Perl itself.
perl v5.10.0 2009-09-02 XML::SAX::Machines(3pm)