in reply to Re: XML::XPath
in thread XML::XPath

Interesting, I had never thought about using ignore_elts to effectively delete elements. That's smart though. You just have to be sure that you don't ever have any other element in datarec. I would maybe add an extra $drec->cut_children at the beginning of add_filename, just in case. Fixed formats seem to have a natural tendency to evolve over time. ;--(

You could get a slightly shorter, and I think nicer looking code, by using the insert_new_elt method:

$elt = new XML::Twig::Elt('fileoffset','0'); $elt->paste('last_child',$drec);

becomes:

    $drec->insert_new_elt( last_child => 'fileoffset', '0');