in reply to Re: Using XML modules to remove XML elements
in thread Using XML modules to remove XML elements

The root element of the document is <bulk-load> the document is made up of the <journal> elements. The entire document is close to 3 MB. I am looking into XML::DOM, since I am unfamiliar with XML modules used in Perl. I appreciate your advice..thanks.
  • Comment on Re^2: Using XML modules to remove XML elements

Replies are listed 'Best First'.
Re^3: Using XML modules to remove XML elements
by gellyfish (Monsignor) on Aug 05, 2004 at 15:32 UTC

    IN that case you can do something like:

    use XML::DOM; + + my $xml = 'jj.xml'; my $parser = new XML::DOM::Parser; my $doc = $parser->parsefile($xml); + my $nodes = $doc->getElementsByTagName ("ISSN"); + foreach my $node (@{$nodes}) { if ( $node->getFirstChild()->toString() eq '1742-7061' ) { my $parent = $node->getParentNode(); $doc->getFirstChild()->removeChild($parent); } + } + print $doc->toString();
    Of course in your production code you will want to have all the ISSN numbers you want removed in a hash and do exists rather than the single comparison I have there.

    /J\

      Great!!! Thanks a lot..XML::DOM definitely seems to be an easier alternative..