The short answer is to encode a URL like any other text in a document. You will not be mistaken if you replace the characters as follows:
& -> & ' -> ' " -> " < -> < > -> >
(and anyone who reads a document with the appropriate parser will receive the correct text, i.e. unencoded text).
However, I would repeat Anthony's comment: why do you think you need to worry about this? Any reasonable XML writer should take the text you want to represent and make the encoding itself (just like the parser will override the encoding). Your application should only deal with uncoded text, and it should rely on an XML record library to handle character encoding and maintain correctness. Otherwise, you run a risk called bozo . XmlTextWriter seems to be an API.net that makes all the necessary changes.
source share