"... and it outputs an XML file with the apostrophes and quotation marks intact."

But the OP wanted the apostrophes and quotation marks encoded into " and &pos; however.

The source for XML::Writer has this routine defined:

sub _escapeLiteral { my $data = $_[0]; if ($data =~ /[\&\<\>\"]/) { $data =~ s/\&/\&amp\;/g; $data =~ s/\</\&lt\;/g; $data =~ s/\>/\&gt\;/g; $data =~ s/\"/\&quot\;/g; } return $data; }
But i am very unclear on how it is being called, if at all.

Here is the code that i used:

use strict; use warnings; use XML::Writer; my %hash = ( str1 => 'one<two', str2 => 'one&two', str3 => 'two>one', str4 => 'Caisse D"Eparge', str5 => q(Caisse D'Eparge), ); my $Writer = XML::Writer->new( OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, ); $Writer->startTag('root'); $Writer->dataElement( $_, $hash{$_} ) for sort keys %hash; $Writer->endTag('root'); $Writer->end(); print $Writer->to_string;
And the results:
<root> <str1>one&lt;two</str1> <str2>one&amp;two</str2> <str3>two&gt;one</str3> <str4>Caisse D"Eparge</str4> <str5>Caisse D'Eparge</str5> </root>
As you can see, the double quote probably should have been encoded but not the single quote. XML::Writer seems very limited in this regard, at the very least, the documentation is unclear on how to customize your usage of the interface (and the code itself is hard to follow).

I would recommend using another XML module, perhaps even recommend using JSON instead if possible.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re^2: How to encode apostrophe and quote using XML::Writer? by jeffa
in thread How to encode apostrophe and quote using XML::Writer? by bcurrens

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.