XML::Elemental::Element - a generic element (tag) object.


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

Index


Code Index:


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

package XML::Elemental::Element;
use strict;
use base qw( XML::Elemental::Node );

sub new {
    my $self = bless {}, $_[0];
    $self->{attribute} = {};
    $self->{contents}  = [];
    return $self;
}

sub text_content {
    return '' unless defined $_[0]->{contents};
    return join('',
        map { $_->can('text_content') ? $_->text_content : $_->data }
          @{$_[0]->contents});
}

sub name {
    $_[0]->{name} = $_[1] if @_ > 1;
    return $_[0]->{name};
}

sub parent {
    $_[0]->{parent} = $_[1] if @_ > 1;
    return $_[0]->{parent};
}

sub contents {
    $_[0]->{contents} ||= [];
    $_[0]->{contents} = $_[1] if @_ > 1;
    return $_[0]->{contents};
}

sub attributes {
    $_[0]->{attributes} ||= {};
    $_[0]->{attributes} = $_[1] if @_ > 1;
    return $_[0]->{attributes};
}

1;

__END__