Update of /cvsroot/net-script/netscript2/src/perl/XML/DOM2
In directory usw-pr-cvs1:/tmp/cvs-serv18750
Added Files:
Attr.pm
Log Message:
* initial checkin
--- NEW FILE: Attr.pm ---
#--------------------------------------------------------
# DOM Level 2 Implementation for Perl
# Class Attr
# $Id: Attr.pm,v 1.1 2001/12/03 21:16:58 derkork Exp $
#
# DOM2 and all related materials, such as documentation,
# are protected under the terms and conditions of the Artistic License.
# (C) 2000-2001 by Jan Thomä, insOMnia
# mailto: ko...@in...
#--------------------------------------------------------
use strict;
package XML::DOM2::Attr;
use base qw(XML::DOM2::Node);
use vars qw($VERSION);
use XML::DOM2::DOMException;
#--------------------------------------------------------
# Globals
#--------------------------------------------------------
$VERSION = '1.0';
#--------------------------------------------------------
# Methods
#--------------------------------------------------------
#/**
# Creates a new XML::DOM2::Attr.
# @return an instance of XML::DOM2::Attr.
#*/
sub new {
my ($proto) = shift;
my $class = ref( $proto ) || $proto;# get the Classname
my $this = $proto -> SUPER::new(@_);
$this -> { m_name } = "";
$this -> { m_ownerElement } = undef;
$this -> { m_specified } = 0;
$this -> { m_value } = "";
return $this;
}
#/**
# Returns the name of this attribute.
# @return the name of this attribute.
# @public
#*/
sub name {
my ($this) = @_;
$this -> { m_name };
}
#/**
# Returns the owner element of this attribute, or undef, if there
# is no owner element.
# @public
#*/
sub ownerElement {
my ($this) = @_;
$this -> { m_ownerElement };
}
#/**
# Returns the value of this attribute. On retrieval, the value
# is returned as a string. Character and general entity references
# are replaced with their values. On setting, this creates a text
# node with the unparsed contents of the string, i.e any characters
# that an XML processor would recognize as markup are instead treated
# as literal text.
# @param (optional) a hash containing the following key-value-pairs
# value - the new value of the string.
# @return the value of this attribute.
#*/
sub value {
my ($this, $paramRef) = @_;
if ( defined($paramRef) ) {
my %params = %{$paramRef};
my $value = $params{"value"};
# clear list of children
$this -> childNodes() -> removeAll();
# append new node
my $textNode = $this -> ownerDocument() -> createTextNode(
{ data => $value } );
$this -> appendChild( { newChild => $textNode } );
$this -> { m_specified } = 1;
}
# now convert all child nodes (which can be text or entity references)
# to string and concatenate them.
my $result = "";
my $count = $this -> childNodes() -> length() -1;
for (1 .. $count ) {
# FIXME: Support for entity references
my $node = $this -> childNodes() -> item( $_ );
if ( $node -> nodeType() = &TEXT_NODE() ) {
$result .= $node -> nodeValue();
}
}
$result;
}
#/*
# If this attribute was explicitly given a value in the
# original document, this is true, otherwise this is false.
# @return a boolean telling whether this attr was specified or not
# @public
#*/
sub specified {
my ($this) = @_;
if ( defined( $this -> ownerElement() ) ) {
$this -> m_specified;
}
else {
1;
}
}
#/**
# Returns ATTRIBUTE_NODE.
# @public
#*/
sub nodeType {
&ATTRIBUTE_NODE();
}
|