Thanks for the explanation,
mirod.
I'm typically creating XML that dead-ends into a typesetting system (and may need its structure changed on a whim); therefore, DTDs are not created, and, as a result, my knowledge of them remains scant.
For my fellow SOPW, here's what I ended up with (I changed the content of
element so the example would make a little more sense):
use strict;
use warnings;
use XML::Twig;
my $XML = XML::Twig->new(
pi => 'process',
pretty_print => 'indented',
twig_roots => {
'element' => sub {
for my $child ($_->cut_children()) {
if ($child->is_pcdata()) {
for my $piece (split /(Warning:)/i, $child->trimme
+d_text()) {
my $pcdata = XML::Twig::Elt->new('#PCDATA' =>
+$piece);
if ($piece =~ /Warning:/i) {
my $b_start = XML::Twig::Elt->new('#PI');
$b_start->set_target('xpp');
$b_start->set_data('bold');
my $b_end = XML::Twig::Elt->new('#PI');
$b_end->set_target('xpp');
$b_end->set_data('/bold');
$b_start->paste('last_child', $_);
$pcdata->paste('last_child', $_);
$b_end->paste('last_child', $_);
}
else {
$pcdata->paste('last_child', $_);
}
}
}
else {
$child->paste('last_child', $_);
}
}
$_->flush();
}
},
);
$XML->parse(*DATA);
print "\n";
__DATA__
<root>
<element>A sentence about the product<?xpp qa?>Warning: This may s
+pontaneously combust.</element>
</root>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.