XML::DTD::Notation - Perl module representing a notation declaration in a DTD


XML-DTD documentation Contained in the XML-DTD distribution.

Index


Code Index:

NAME

Top

XML::DTD::Notation - Perl module representing a notation declaration in a DTD

SYNOPSIS

Top

  use XML::DTD::Notation;

  my $not = XML::DTD::Notation->new('<!NOTATION e PUBLIC "+//F//G//EN">');

DESCRIPTION

Top

XML::DTD::Notation is a Perl module representing a notation declaration in a DTD. The following methods are provided.

new
 my $not = XML::DTD::Notation->new('<!NOTATION e PUBLIC "+//F//G//EN">');

Construct a new XML::DTD::Notation object.

name
 print $not->name;

Return the notation name

sysid
 print $not->sysid;

Return the notation sysid

pubid
 print $not->pubid;

Return the notation pubid

SEE ALSO

Top

XML::DTD, XML::DTD::Component

AUTHOR

Top

Brendt Wohlberg <wohl@cpan.org>

COPYRIGHT AND LICENSE

Top

ACKNOWLEDGMENTS

Top

Peter Lamb <Peter.Lamb@csiro.au> improved parsing of NOTATION declarations.


XML-DTD documentation Contained in the XML-DTD distribution.

package XML::DTD::Notation;

use XML::DTD::Component;
use XML::DTD::Error;

use 5.008;
use strict;
use warnings;

our @ISA = qw(XML::DTD::Component);

our $VERSION = '0.09';


# Constructor
sub new {
  my $arg = shift;
  my $not = shift;

  my $cls = ref($arg) || $arg;
  my $obj = ref($arg) && $arg;

  my $self;
  if ($obj) {
    # Called as a copy constructor
    $self = { %$obj };
    bless $self, $cls;
  } else {
    # Called as the main constructor
    $self = { };
    bless $self, $cls;
    $self->define('notation', $not, '<!NOTATION', '>');
  }
  return $self;
}


# Return the notation name
sub name {
  my $self = shift;

  return $self->{'NAME'};
}


# Return the notation sysid
sub sysid {
  my $self = shift;

  return $self->{'SYSTEM'};
}


# Return the notation pubid
sub pubid {
  my $self = shift;

  return $self->{'PUBLIC'};
}


# Parse the notation declaration
sub _parse {
  my $self = shift;
  my $entman = shift;
  my $nttdcl = shift;

  if ($nttdcl=~/<\!NOTATION\s+([\w\.:\-_]+|%[\w\.:\-_]+;)\s+(SYSTEM|PUBLIC)\s+([\"\'])(.*?)\3\s+(?:([\"\'])(.*?)\5)?\s*>/s) {
    my $name = $1;
    my $type = defined($2) ? $2 : '';

    if ($type eq 'SYSTEM') {
      $self->{'SYSTEM'} = $4;
      throw XML::DTD::Error("SYSTEM notation has two identifiers in ".
			      "definition: $nttdcl", $self) if (defined $6);
    } elsif ($type eq 'PUBLIC') {
      $self->{'SYSTEM'} = $6 if (defined $6);
      $self->{'PUBLIC'} = $4;
    } else {
      throw XML::DTD::Error("Notation neither PUBLIC nor SYSTEM in ".
			      "definition: $nttdcl", $self);
    }
    $name = $entman->peexpand($name)
      if ($name =~ /^%([\w\.:\-_]+);$/);
    $self->{'NAME'} = $name;

  } else {
    throw XML::DTD::Error("Error parsing notation definition: $nttdcl", $self);
  }
}


1;
__END__