Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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>

In reply to Re^3: XML::Twig and Processing Instructions by eff_i_g
in thread XML::Twig and Processing Instructions by eff_i_g

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found