Encode all characters for xml

I am trying to ensure that text from a db can be used validly in xml. I was using htmleditformat to sort out things like &, but I now have a problem with £ signs getting through.

What can i so to ensure all characters which will error xml are correctly encoded?



I have one application where I use all three of the items below. I am not sure you can filter for all so rereplace allows you to redefine the really odd ones.


This is the simplest method. It converts special chars to their ascii description – example doublequote(“) becomes &quote;

This does not convert spaces in the text string but may also increase the length of the string.

#URLEncodeFormat(textstring)# - #urlDecode(textstring)#

This method converts all special characters including spaces to their ascii equivalent.

You would use urlDecode to display the values without the encoding.

The drawback to this method is that if you store the text in a database it may exceed the fields defined width.

#reReplace(“textstring”, “chars”, “replacement value”, “All or 1”)#

Replacing special characters can also be done. You can replace them with spaces or underscores or even text strings.

I’m surprised that htmleditformat doesnt encode a £ sign - do you know where i can find a list of what it does encode?