Alvis::NLPPlatform::XMLEntities - Perl extension for managing characters which can not be used in a XML


Alvis-NLPPlatform documentation Contained in the Alvis-NLPPlatform distribution.

Index


Code Index:

NAME

Top

Alvis::NLPPlatform::XMLEntities - Perl extension for managing characters which can not be used in a XML document

SYNOPSIS

Top

use Alvis::NLPPlatform::XMLEntities;

Alvis::NLPPlatform::XMLEntities::decode($line);

Alvis::NLPPlatform::XMLEntities::eecode($line);

DESCRIPTION

Top

This module is used to encode or decode special XML characters (&, ', ", >, <).

METHODS

Top

encode($line)

This method encodes special XML characters as XML entities in the line $line.

decode($line)

This method decodes XML entities corresponding to special XML characters in the line $line . It returns the shift in the offset after substitution;

SEE ALSO

Top

Alvis::NLPPlatform

Alvis web site: http://www.alvis.info

AUTHORS

Top

Guillaume Vauvert <guillaume.vauvert@lipn.univ-paris13.fr>

Currently maintained by Julien Deriviere <julien.deriviere@lipn.univ-paris13.fr> and Thierry Hamon <thierry.hamon@lipn.univ-paris13.fr>

LICENSE

Top

Copyright (C) 2004 by Guillaume Vauvert, Thierry Hamon and Julien Deriviere

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.


Alvis-NLPPlatform documentation Contained in the Alvis-NLPPlatform distribution.
package Alvis::NLPPlatform::XMLEntities;
use strict;

use warnings;

our $VERSION=$Alvis::NLPPlatform::VERSION;

sub encode
{
    $_[0]=~s/&/&amp;/g;
    $_[0]=~s/\"/&quot;/g;
    $_[0]=~s/\'/&apos;/g;
    $_[0]=~s/</&lt;/g;
    $_[0]=~s/>/&gt;/g;
}




sub decode
{
    my $shift_offset = 0;

    $shift_offset += ($_[0]=~s/&quot;/\"/g) * 5;
    $shift_offset += ($_[0]=~s/&apos;/\'/g) * 5;
    $shift_offset += ($_[0]=~s/&amp;/&/g) * 4;
    $shift_offset += ($_[0]=~s/&lt;/</g) * 3;
    $shift_offset += ($_[0]=~s/&gt;/>/g) * 3;
    return($shift_offset);
}


1;

__END__