sharief has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I am developing a site in perl/cgi for an e-publishing company where they use a lot of special characters. I get their error reports in input box and store it in xml. But while retrieving it all the special characters change into entities it seems html parses them and i am unable to generate the special characters on page as it is.

Example:
XML: <error>Missed &reg; in line 2</error> <error>Missed <h1> tag in line 8</error> HTML: <textarea>Missed &reg; in line 2,Missed <h1> tag in line 8 </textarea>

I want the same the text as &reg; but not as a symbol ® inside the textarea but it changes into its appropriate entity.

SInce it ia an epublishing company they use hundreds of special characters and its very hard to include escape sequences for each of them

Any help on this! I am searching on google din get any stuff is there any tag or header declaration to show those entities as raw text but not symbols on the page even i am searching pls help me monks

Replies are listed 'Best First'.
Re: Special characters in perl/cgi
by marto (Cardinal) on Feb 13, 2012 at 16:49 UTC
Re: Special characters in perl/cgi
by choroba (Cardinal) on Feb 13, 2012 at 16:43 UTC
    Just replace & with &amp; and < with &lt;. What you show as XML is not a real XML, because &reg; is not an XML entity. You want
    <error>Missed &amp;reg; in line 2</error> <error>Missed &lt;h1> tag in line 8</error>
Re: Special characters in perl/cgi
by tangent (Parson) on Feb 13, 2012 at 19:12 UTC
    HTML::Entities also allows you to supply your own character mapping, something I have found very useful. If you look at the source code of that module you will see how to build the map. See also the chr() and ord() functions for another way to represent these characters in Perl. BTW not escaping HTML tags like <H1> can seriously break your form.