I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2007-06-23 05:39:09-07 by mirod in response to 5514
Re: Modify a compex XML documaent with XML::Twig

I don't know exactly what you want to do, so it's a little difficult to give you a specific answer, but here is a piece of code that will hopefully be of some help. It locates the proper comment through its Prompt sibling, then perfoems a string substitution on it. Alternatively you could replace completely the CDATA section in the element by doing $response->set_cdata( 'your text here').

Note that there might be a bug in the released version of the module (the root start tag might be output twice, at least that was the case with the development version of XML::Twig) so you might want to grab the latest bestest version (dated June 23) from xmltwig.com

#!/usr/bin/perl use strict; use warnings; use XML::Twig; XML::Twig->new( twig_roots => { Comments => \&comments }, twig_print_outside_roots => 1, keep_spaces => 1, ) ->parsefile( 'resume.xml'); exit; sub comments { my( $t, $comments)= @_; if( $comments->field( 'Prompt')=~ m{Briefly describe your qualifications for this position}) { my $response= $comments->first_child( 'Response'); if( $response) { $response->subs_text( qr{some_company}, 'The Bestest Company Evar'); } } $t->flush; }
Direct Responses: 5520 | 5523 | Write a response