If you actually want to do this as part of a larger system where running xml_grep would be a lesser-desired choice, XML::Twig is actually not that hard to use, once you get around its huge documentation ;-). You can also read some better docs on its website. Anyway, once you've loaded your XML file in to memory, you can just find the twig you're interested in (see get_xpath), and then just tell the object to "cut()" itself out, and you're done. You just need to print out the resultant XML to wherever you want.

use XML::Twig; my $xml = XML::Twig->new(); $xml->parsefile('foo.xml'); foreach my $el ($xml->get_xpath('dummy_record')) { $el->cut(); } $xml->print(\*STDOUT);

In reply to Re: Parsing XML file and removing the element by Tanktalus
in thread Parsing XML file and removing the element by sananpah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.