libxml-enno

 view release on metacpan or  search on metacpan

lib/XML/Handler/BuildDOM.pm  view on Meta::CPAN

    my $node = $doc->createElement ($elem);
    $self->{Element} = $node;
    $parent->appendChild ($node);
    
    my $i = 0;
    my $n = scalar keys %$attr;
    return unless $n;

    if (exists $hash->{AttributeOrder})
    {
	my $defaulted = $hash->{Defaulted};
	my @order = @{ $hash->{AttributeOrder} };
	
	# Specified attributes
	for (my $i = 0; $i < $defaulted; $i++)
	{
	    my $a = $order[$i];
	    my $att = $doc->createAttribute ($a, $attr->{$a}, 1);
	    $node->setAttributeNode ($att);
	}

	# Defaulted attributes
	for (my $i = $defaulted; $i < @order; $i++)
	{
	    my $a = $order[$i];
	    my $att = $doc->createAttribute ($elem, $attr->{$a}, 0);
	    $node->setAttributeNode ($att);
	}
    }
    else
    {
	# We're assuming that all attributes were specified (1)
	for my $a (keys %$attr)
	{
	    my $att = $doc->createAttribute ($a, $attr->{$a}, 1);
	    $node->setAttributeNode ($att);
	}
    }
}

sub end_element
{
    my $self = shift;
    $self->{Element} = $self->{Element}->getParentNode;
    undef $self->{LastText};

    # Check for end of root element
    $self->{EndDoc} = 1 if ($self->{Element} == $self->{Document});
}

sub entity_reference # was Default
{
    my $self = $_[0];
    my $name = $_[1]->{Name};
    
    $self->{Element}->appendChild (
			    $self->{Document}->createEntityReference ($name));
    undef $self->{LastText};
}

sub start_cdata
{
    my $self = shift;
    $self->{InCDATA} = 1;
}

sub end_cdata
{
    my $self = shift;
    $self->{InCDATA} = 0;
}

sub comment
{
    my $self = $_[0];

    local $XML::DOM::IgnoreReadOnly = 1;

    undef $self->{LastText};
    my $comment = $self->{Document}->createComment ($_[1]->{Data});
    $self->{Element}->appendChild ($comment);
}

sub doctype_decl
{
    my ($self, $hash) = @_;

    $self->{DocType}->setParams ($hash->{Name}, $hash->{SystemId}, 
				 $hash->{PublicId}, $hash->{Internal});
    $self->{SawDocType} = 1;
}

sub attlist_decl
{
    my ($self, $hash) = @_;

    local $XML::DOM::IgnoreReadOnly = 1;

    $self->{DocType}->addAttDef ($hash->{ElementName},
				 $hash->{AttributeName},
				 $hash->{Type},
				 $hash->{Default},
				 $hash->{Fixed});
}

sub xml_decl
{
    my ($self, $hash) = @_;

    local $XML::DOM::IgnoreReadOnly = 1;

    undef $self->{LastText};
    $self->{Document}->setXMLDecl (new XML::DOM::XMLDecl ($self->{Document}, 
							  $hash->{Version},
							  $hash->{Encoding},
							  $hash->{Standalone}));
}

sub entity_decl
{
    my ($self, $hash) = @_;
    
    local $XML::DOM::IgnoreReadOnly = 1;

    # Parameter Entities names are passed starting with '%'
    my $parameter = 0;



( run in 1.284 second using v1.01-cache-2.11-cpan-63c85eba8c4 )