XML::DTD::Text - Perl module representing text (primarily whitespace) in a DTD


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

Index


Code Index:

NAME

Top

XML::DTD::Text - Perl module representing text (primarily whitespace) in a DTD

SYNOPSIS

Top

  use XML::DTD::Text;

  my $txt = XML::DTD::Text->new('    ');

DESCRIPTION

Top

  XML::DTD::Text is a Perl module representing text (primarily
  whitespace) in a DTD. The following methods are provided.




new
 my $txt = XML::DTD::Text->new('    ');

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

writexml
 $xo = new XML::Output({'fh' => *STDOUT});
 $txt->writexml($xo);

Write an XML representation of the text.

SEE ALSO

Top

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

AUTHOR

Top

Brendt Wohlberg <wohl@cpan.org>

COPYRIGHT AND LICENSE

Top


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

package XML::DTD::Text;

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 $txt = 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
    throw XML::DTD::Error("Constructor for XML::DTD::Textcalled ".
			  "with undefined text") if (! defined($txt));
    $self = { };
    bless $self, $cls;
    ##$txt =~ s/\n/<br\/>/sg;
    $self->define('wspace', $txt);
  }
  return $self;
}


# Write an XML representation
sub writexml {
  my $self = shift;
  my $xmlw = shift;

  my $tag = $self->{'CMPNTTYPE'};
  my $txt = $self->{'UNPARSEDTEXT'};
  my $tmp = $txt;
  $tmp =~ s/[^\n]//g;
  my $nlf = length($tmp);
  $txt =~ s/\n/\&\#xA;/g;
  $xmlw->open($tag, {'nlf' => $nlf});
  $xmlw->pcdata($txt);
  $xmlw->close;
}


1;
__END__