John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
But, here is something different. I'm using a word with an @ in front of it to indicate a cross-reference. Here is the general idea in plain text:
Only really I'll analyse the word in $1 and generate a <A class='code'> rather than an ordinary TT, but you get the idea. I'm inserting an element in the middle of a #PCDATA node.$text =~ s/@(\w+)/<TT>$1<\/TT>/g;
So two questions:
1) how do I do that using XML::Twig? my first thought is to produce a list of text and Elt's and then use set_content, which I beleive will replace what was a single PCDATA with mixed content. So, break the text into runs of normal (generates a string in the list) and @word (generates an element object).
2) what's a good way to break the string into runs like this? The RE above finds the @word areas, but I need to preserve what's in between, too. Ideas thus far: use something like ([^@]+)(@\w+) in the re/g to find consecutive string/word pairs that should abut each other. But the (possible) odd one on the ends complecates matters. Or, use split on '@' and then take the first word of each resulting part (except for the first). Any better ideas?
—John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig approach/architecture/design question
by mirod (Canon) on Nov 05, 2001 at 14:19 UTC | |
by John M. Dlugosz (Monsignor) on Nov 06, 2001 at 01:15 UTC | |
|
Re (tilly) 1: XML::Twig approach/architecture/design question
by tilly (Archbishop) on Nov 05, 2001 at 20:33 UTC | |
by mirod (Canon) on Nov 05, 2001 at 21:02 UTC | |
by John M. Dlugosz (Monsignor) on Nov 05, 2001 at 21:49 UTC | |
by John M. Dlugosz (Monsignor) on Nov 05, 2001 at 21:39 UTC | |
by tilly (Archbishop) on Nov 05, 2001 at 22:10 UTC | |
by John M. Dlugosz (Monsignor) on Nov 06, 2001 at 01:03 UTC |