unknown_varmit has asked for the wisdom of the Perl Monks concerning the following question:
Here is the code I am developing. The &choiceReplace sub simply searches through the passed argument string and replaces matched words (which will most always alter the length of the string).Example text: <paragraph> Some <bold>text</bold> here which may be any <bold>length< +/bold> and <bold>contain</bold> a number of child tags.</paragraph>
The child text from the paragraph tag may contain replaced search words. When this is true, the set_text command replaces the <bold> tags with just a text string. I understand why this occurs, but is there a better method of cycling through the <paragraph> children text without affecting the <bold> tags? It seems to me that I need to move through each individual child tag by tag. Is this possible without knowing what tags/text I might encounter? Will the mixed content allow me to alter just the <paragraph> text? And still maintain the <bold> tags?use XML::Twig; my $twig = new XML::Twig(TwigHandlers => { 'bold' => \&bold, 'p' => \ +¶graph, 'li' => \&ordered_list},TwigRoots => {body => 1}); sub bold { my ($twig, $bold,) = @_; my $bold_text = $bold->text; &choiceReplace($bold_text,$file); $bold->set_text($bold_text); } sub paragraph { my ($twig, $para,) = @_; my $para_text = $para->text; &choiceReplace($para_text,$file); $bold->set_text($bold_text); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Twig Mixed Content Child Text Replace Issues
by ajguitarmaniac (Sexton) on Feb 08, 2011 at 09:27 UTC | |
|
Re: Twig Mixed Content Child Text Replace Issues
by mirod (Canon) on Feb 08, 2011 at 10:04 UTC | |
by unknown_varmit (Initiate) on Feb 08, 2011 at 15:33 UTC | |
by mirod (Canon) on Feb 08, 2011 at 16:18 UTC | |
by unknown_varmit (Initiate) on Feb 08, 2011 at 22:18 UTC |