####################################### # Service Parts for InstantXML # 1999 (C) UENO Kojun # ####################################### =description ** How to use this pm ** Put this pm into your directory (ex. InstantXML) and 'use' it (ex. use InstantXML::{this pm}) ** What you can do ** 1)You can release memory deleting $your_node and its children. According to my test, this subroutine wasn't effective for the XML::DOM node. 2)You can access some attributes with compatible names with the XML::DOM. ** Maybe it will be like this ** use InstantXML::KParser; use SP1for053; while (....) { $top_node = InstantXML::KParser->parseFragment($str); ..... &assert($your_nl->getLength == $your_nl->get_length); ..... InstantXML::SP::instant_obliterate($n_doc); # Bye } =cut use Carp; if (defined $InstantXML::version) { carp("This SP may be too old."); return 1; } #### Compatibility with the XML::DOM #### package InstantXML::DOM::Level1::TmpNode; sub getDocumentElement { return shift->get_documentElement; } sub getChildNodes { return shift->get_childNodes; } package InstantXML::DOM::Level1::TmpNode; sub getAttributes { return $_[0]->get_attributes; } package InstantXML::DOM::Level1::TmpNodeList; sub getLength { return shift->get_length; } package InstantXML::DOM::Level1::TmpNamedNodeMap; sub getLength { return $_[0]->get_length; } package InstantXML::DOM::Level1::TmpAttribute; sub getValue { return $_[0]->get_value; } # There are many more though.... # XML::DOM # my $parser = new XML::DOM::Parser; # my $doc = $parser->parse ($str); # my $n_post = $doc->getDocumentElement; # InstantXML # my $n_fra = InstantXML::KParser->parseFragment($str); # my $n_post = $n_fra->get_childNodes->item(0); # sub parseDocument { returns doc } #### RD version renamed Attribute as Attr #### package InstantXML::DOM::Level1::TmpDocument; sub createAttr { my ($this, $name) = @_; return $this->createAttribute($name); } package InstantXML::DOM::Level1::TmpNode; sub ATTRIBUTE_NODE {2} #### Cyclic reference compliant #### package InstantXML::DOM::Level1::TmpNode; sub instant_obliterate { InstantXML::SP::instant_obliterate(shift); } package InstantXML::SP; sub instant_obliterate { my $targ = shift; my $nl = $targ->getChildNodes; return unless (defined $nl); return unless ($nl->getLength > 0); for ($i = 0; $i < $nl->getLength; $i++) { &instant_obliterate($nl->item($i)); } my $targmap = $targ->getAttributes; if (0 and $targmap) { for ($i = 0; $i < $targmap->getLength; $i++) { $a = $targmap->item($i); undef $a; } undef $targmap; } # undef $targ->{'parentNode'}; delete $targ->{'childNodes'}; } 1;