Skip navigation.
 
mlRe: Encoding a string for HTML
FROM : Norman Gray
DATE : Fri Jul 21 00:13:50 2006

On 2006 Jul 20 , at 18.18, David Dunham wrote:

>>>> I'm trying to output a string suitable for using in HTML -- no 
>>>> troublesome characters like < and >.


and later:

>  the actual intent is to use within XML not HTML. So maybe I should 
> remove "xml" from the exclusions and it will handle " ?


There's no need to encode " in XML either.  The only characters that 
need to be escaped in XML (or HTML) body content are &lt; and &amp;. 
Even &gt; doesn't have to be escaped -- it's only there for 
symmetry.  You don't even have to escape non-ASCII characters, since 
XML files are Unicode.

Or are you trying to escape the string for use within an attribute 
value?  In that case you will additionally have to escape ' or " 
unless you're using the other one as the attribute value delimiter, 
but the suggested (by the spec) &apos; and &quot; aren't defined by 
the spec.  Having elaborate strings in attributes is probably a poor 
idea, but if you didn't design the DTD, you're stuck with it.

All the best,

Norman


--
------------------------------------------------------------------------
----
Norman Gray  /  http://nxg.me.uk
eurovotech.org  /  University of Leicester, UK

Related mailsAuthorDate
mlEncoding a string for HTML David Dunham Jul 20, 06:25
mlRe: Encoding a string for HTML Douglas Davidson Jul 20, 18:36
mlRe: Encoding a string for HTML David Dunham Jul 20, 19:18
mlRe: Encoding a string for HTML Douglas Davidson Jul 20, 20:12
mlRe: Encoding a string for HTML Peter Bierman Jul 20, 20:41
mlRe: Encoding a string for HTML Norman Gray Jul 21, 00:13
mlRe: Encoding a string for HTML David Dunham Jul 21, 00:26
mlRe: Encoding a string for HTML Norman Gray Jul 21, 11:40