in reply to Using XML modules to remove XML elements

Do you have the structure you have shown in a larger document, with enclosing elements? If so it would be possible to use, say, XML::DOM to find all the ISSN nodes and if they match the requirement then you can delete the parents.

/J\

  • Comment on Re: Using XML modules to remove XML elements

Replies are listed 'Best First'.
Re^2: Using XML modules to remove XML elements
by eraymond (Novice) on Aug 05, 2004 at 15:21 UTC
    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.

      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..