I need to pass XML data through a filter that will transform the character data but leave the tags as-is. (The transform involves converting certain ASCII characters to utf8 Arabic characters, so I have to make sure this doesn't apply to the tags).
XML::Parser, with the "Style" set to "Stream" makes this very easy and clear, but there's one problem: if the input contains empty tags like this:
<sometag attr1="v1" attr2="v2"/>
it'll come out looking like this:
<sometag attr1="v1" attr2="v2"></sometag>
Am I just being too picky? Is it too much to ask that empty tags be kept empty? Here's a brief snippet that demonstrates the behavior:
use XML::Parser;
$xml = qq{<tag attr="xyz"/>};
print "original: $xml\n";
$parser = new XML::Parser( Style => 'Stream' );
print "parsed: ";
$parser->parse( $xml );
print "\n";
sub StartTag { print }
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.