The problem is that XML::DOM is a maze of objects. And each node object can only have one parent. So you first stick the <record> object in place of the first Thammasat and then MOVE the object in place of the second. You'd have to create a brand new $ritem each time you want to replace the original.

To tell the truth, you'd most likely do better if you dumped the module and used a different. I'm surprised mirod did not already suggest his XML::Twig, anyway I'll suggest my XML::Rules:

use strict; use XML::Rules; my $link = "Thammasat"; my $rlinks = { "institute" => ["test"], "year" => ["test"], "degree" => ["test"], "faculty" => ["test"], "major" => ["test"], "gpa" => ["test"], }; my $parser = XML::Rules->new( style => 'filter', ident => ' ', rules => { _default => 'raw extended', record => sub { return $_[0] => $_[1] unless $_[1]->{':institute'}{_conten +t} eq $link; return $_[0] => $rlinks; } }, ); $parser->filterfile('employee.xml', 'employee-filtered.xml');

The additional advantage is that this scripts doesn't load the whole file into memory, it parses the file, copies everything outside the <record> tag and only ever remembers that single tag with contents.


In reply to Re^3: XML::DOM - NOT_FOUND_ERR by Jenda
in thread XML::DOM - NOT_FOUND_ERR by sureerat

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.