PerlingTheUK has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am currently trying to get rid of some useless junk in an XML file. Infortunately when I use the removeChild function, The compilation is aborted. This occurs without any other error message using AS Perl 5.8.6 on Windows XP Pro. The code is as follows:
sub remove_element { my $elem = shift; my @children = @{$elem->getChildNodes()}; if (@children == 0 ){ print $elem->toString; my $parent = $elem->getParentNode(); $parent->removeChild( $elem ); return; } for my $child ( @children ){ print $child->toString(); remove_element( $child ); } }

Cheers,
PerlingTheUK

Replies are listed 'Best First'.
Re: Crash on XML::DOM Remove Child
by rg0now (Chaplain) on Mar 09, 2005 at 00:27 UTC
    I am not entirely sure if I understand your question correctly.

    You seem to indicate that if you give the above code to perl -MXML::DOM  -e, then it ceases to compile. If this is the case, then I can not reproduce this on Debian Linux testing, Perl 5.8.4. Yet, if this is the case, then I pretty much recommend you reporting this at the perl-xml mailinglist (Perl-XML <at> listserv.ActiveState.com). I have got some really useful tips there in the past with similar problems.

    On the other hand, if you mean that your code crashes when it gets to executing removeChild(), neither this I can reproduce on Linux, so it must be the first case...

    rg0now

      No, It compiles fine and reads the xml File. I then want to delete some parts of it before writing a smaller file. When running the quoted function, it exits with the given error message (as in the Xemacs window) and exits. I am not sure if this is something I do wrong or if there is a bug in the AS - Version of my XML::DOM.

      Cheers,
      PerlingTheUK
        What I don't really understand is that what makes you think that it is the removeChild method that causes the crash. Have you tried to debug the program? Have you tried to place print statements to narrow the possibility of a wrong guess?

        If the problem persists and you can reproduce it on other boxen/platforms, please, try to post the XML snippet and the (shortened) code here or the perl-xml list, and I will try to hunt it down.

        rg0now