NAME

XML::Filter::Normalize - Clean up SAX event streams

VERSION

Version 0.01

SYNOPSIS

  # Just like any normal SAX filter.
  my $w    = XML::SAX::Writer->new();
  my $norm = XML::Filter::Normalize->new( Handler => $w );
  my $p    = XML::SAX::ParserFactory->parser( Handler => $handler );

  # If you want your SAX consumer to always have well formed events.
  package My::Filter;
  sub new {
    my $class = shift;
    my $self = $self->SUPER::new( @_ );
    return XML::Filter::Normalize->new( Handler => $self );
  }

DESCRIPTION

This class implements a "clean up" filter for SAX events. It's mostly intended to be used by authors of SAX serializers (eg: XML::SAX::Writer, XML::Genx::SAXWriter). If the input event stream is incomplete in some fashion, it will attempt to correct it before passing it on. If it cannot correct it, an exception will be thrown.

PUBLIC METHODS

The following methods are implemented. All others are handled directly by XML::SAX::Base.

start_document()
start_prefix_mapping()
start_element()
end_element()
end_prefix_mapping()
end_document()

These are standard SAX event handlers, which are overridden.

PRIVATE METHODS

These should not be called directly.

correct_element_data()

Given an XML::NamespaceSupport object and a Data hash from a SAX element event, attempt to ensure it conforms to the SAX specification. This method corrects the main hash, and all subordinate attribute hashes. It also ensures that the keys of the attribute hashes are correct (ie, they match the NamespaceURI and LocalName values).

If it does not find at least a LocalName, it will throw an exception.

extract_name_tuple()

Given a hash with some or all of NamespaceURI, Prefix, LocalName and Name keys, try to work out the missing ones.

  • Tries to get Prefix from Name.

  • Tries to get LocalName from Name.

  • Tries to get NamespaceURI from Prefix.

  • Tries to get Prefix from NamespaceURI.

  • Forces returned Name to conform to the values for Prefix and LocalName.

Returns the values for NamespaceURI, Prefix, LocalName and Name in that order.

nsup()

Accessor for an XML::NamespaceSupport object.

whinge()

Throw a new exception of the class XML::Filter::Normalize::Exception.

SEE ALSO

XML::NamespaceSupport, XML::Genx::SAXWriter, XML::SAX::Base, XML::SAX::Writer.

The conversation that started this module on the perl-xml mailing list. http://aspn.activestate.com/ASPN/Mail/Message/Perl-XML/2858464

The Perl SAX spec, http://perl-xml.sourceforge.net/perl-sax/.

AUTHOR

Dominic Mitchell, <cpan (at) happygiraffe.net>

BUGS

Please report any bugs or feature requests to bug-xml-filter-normalize@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Filter-Normalize. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Copyright 2005 Dominic Mitchell, all rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.