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


XML-Filter-Normalize documentation  | view source Contained in the XML-Filter-Normalize distribution.

Index


NAME

Top

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

VERSION

Top

Version 0.01

SYNOPSIS

Top

  # 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

Top

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

Top

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

Top

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

Top

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

Top

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

BUGS

Top

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

Top


XML-Filter-Normalize documentation  | view source Contained in the XML-Filter-Normalize distribution.