XML安全URL编码? [英] XML Safe URLEncoding?

查看:144
本文介绍了XML安全URL编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何连接code,这将是XML安全的网址,其中的符号(安培)?在查询字符串不会破坏XML

How do I encode an URL that will be "xml-safe" where the ampersand(&) in the querystring will not corrupt the XML?

有关实例:

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

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

推荐答案

简短的回答是EN code就像文档中的任何其他文字的网址。你会不会出问题,如果你替换字符如下:

The short answer is to encode the URL just like any other text in the document. You won't go wrong if you replace characters as follows:

& -> &
' -> '
" -> "
< -> &lt;
> -> &gt;

(和任何人读取该文件与符合解析器会得到正确的,即unen codeD,背课文)。

(and anybody reading the document with a conforming parser will get the correct, i.e. unencoded, text back).

不过,我要重申安东尼的评论:为什么你认为你需要担心这一点?任何明智的XML写作系统应该把你要重新present并执行编码本身(就像一个解析器将撤消编码)的文本。您的应用程序应该只处理unen codeD文本,它应该依赖于XML编写的库来处理字符编码和preserving良好性。否则,你的风险被称为笨蛋。它看起来像的XmlTextWriter 是.NET API使所有必要的更改。

However, I would echo Anthony's comment: why do you think you need to worry about this? Any sensible XML writing system should take the text you want to represent and do the encoding itself (just like a parser will undo the encoding). Your application should only have to deal with the unencoded text and it should rely on an XML writing library to deal with character encoding and preserving well-formedness. Otherwise you risk being called a bozo. It looks like XmlTextWriter is the .net API that makes all the necessary changes.

这篇关于XML安全URL编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆