# WWW::Extractor::XML::Element - an abstract superclass for an element of an XML/XHTML/HTML doc
# This is related to HTML::(Toke)Parser, and the constructor is designed to accept
# those tokens out of the box.

package WWW::Extractor::XML::Element;

use strict;
use vars qw(@ISA);

use WWW::Extractor::Generic::Object;
use WWW::Extractor::XML::Element::Text;
use WWW::Extractor::XML::Element::Comment;
use WWW::Extractor::XML::Element::Declaration;
use WWW::Extractor::XML::Element::Lonely;
use WWW::Extractor::XML::Element::Start;
use WWW::Extractor::XML::Element::End;

@ISA = qw|WWW::Extractor::Generic::Object|;

# WWW::Extractor::XML::Element->new('S', $tag, %$attr, @$attr_seq, $orig_text, $has_end)
# WWW::Extractor::XML::Element->new('E', $tag, $orig_text, %$start)
# WWW::Extractor::XML::Element->new('T', $text)
# WWW::Extractor::XML::Element->new('C', $text)
# WWW::Extractor::XML::Element->new('D', $text)

sub new {
    my ($class, $type, @rest) = @_;
    return new WWW::Extractor::XML::Element::Lonely(@rest) if $type eq 'L';
    return new WWW::Extractor::XML::Element::Start(@rest) if $type eq 'S';
    return new WWW::Extractor::XML::Element::End(@rest) if $type eq 'E';
    return new WWW::Extractor::XML::Element::Text(@rest) if $type eq 'T';
    return new WWW::Extractor::XML::Element::Comment(@rest) if $type eq 'C';
    return new WWW::Extractor::XML::Element::Declaration(@rest) if $type eq 'D';
}

1
