XML Safe URLEncoding?

How to encode a URL that will be "xml safe" where the ampersand (&) in querystring will not corrupt the XML?

For instance:

www.somedomain.com/SomePage.aspx?SomeParam=SomeValue&SomeParam2=SomeVal

0
source share
2 answers

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:

& -> &amp; ' -> &apos; " -> &quot; < -> &lt; > -> &gt; 

(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.

+4
source

The AntiXSS library has an XmlEncode method that you could use.

0
source

Source: https://habr.com/ru/post/902840/


All Articles