Hello Guys I am trying to use TWIG module to delete some nodes in a file and print in a new file . It's 2Go bytes files so I tried to parse my XML chunk by chunk but it seems the method that I am using is not working because my file XML is corrupted at the end it's because of the flush which is not reading all the file

Here the code
#--------------------------------------------------------------------- +--------- # This function is to add a twig handler to remove the node in paramet +er #--------------------------------------------------------------------- +--------- sub delete_node { #--------------------------------------------------------------------- +--------- my ($node_to_delete,$file_to_read) = @_; copy($file_to_read,$file_to_read.'-tmp_'.$dateLog.'.xml') open my $file_end, '>', $file_to_read.'-parsed_'.$dateLog.'.xml' my $handlers = {$node_to_delete => section_delete_node($file_end)} +; my $twig = new XML::Twig(pretty_print => 'indented', twig_handlers => $handlers,)->parsefile($f +ile_to_read); close $file_end; if (-s $file_to_read.'-parsed_'.$dateLog.'.xml') { move($file_to_read.'-parsed_'.$dateLog.'.xml', $file_to_read); } else { move($file_to_read.'-tmp_'.$dateLog.'.xml', $file_to_read); } } #--------------------------------------------------------------------- +--------- # This function remove the node in parameter #--------------------------------------------------------------------- +--------- sub section_delete_node { my ($file_end)= @_; return sub { my( $t, $section)= @_; $section->delete(); $t -> flush($file_end); } }

I want for example delete the node dob in my file

<?xml version="1.0" encoding="UTF-8"?> <record category="B" editor="" entered="2000-12-04" sub-category=" +PEP" uid="7320" updated="2018-12-12"> <person ssn="" e-i="E"> <title xsi:nil="true"/> <position xsi:nil="true"/> <names> <first_name/> <last_name>BA</last_name> </names> <agedata> <age xsi:nil="true"/> <as_of_date xsi:nil="true"/> <dob xsi:nil="true"/> <dobs> <dob xsi:nil="true"/> </dobs> <deceased xsi:nil="true"/> </agedata> </person> <details> <id_numbers> <id loc="INT" type="">fd</id> </id_numbers> <place_of_birth xsi:nil="true"/> <locations> <location country="df" city="re" state="">Shahrara</lo +cation> </locations> </details> </record>

And here the result

<?xml version="1.0" encoding="UTF-8"?> <record category="B" editor="" entered="2000-12-04" sub-category=" +PEP" uid="7320" updated="2018-12-12"> <person ssn="" e-i="E"> <title xsi:nil="true"/> <position xsi:nil="true"/> <names> <first_name/> <last_name>BA</last_name> </names> <agedata> <age xsi:nil="true"/> <as_of_date xsi:nil="true"/> <deceased xsi:nil="true"/> </agedata> </person> </record> <details> <id_numbers> <id loc="INT" type="">fd</id> </id_numbers> <place_of_birth xsi:nil="true"/> <locations> <location country="df" city="re" state="">Shahrara</lo +cation> </locations> </details>

If you have some help it would be great . Many Thanks


In reply to XML:twig XML wrong by nico38100

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.