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); }
In reply to Twig Mixed Content Child Text Replace Issues by unknown_varmit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |