开发者

do we need to escape the character '<'

In C# ASP.NET, if we have the characters < or > in a string. Do we need to escape it like:

string a = "\<test\>abcdef\</test\>"

because this string will be send to an external method via webservices. And in that method, it will 开发者_如何学Gobe converted to a some kind of xml file.

contentHtml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + contentHtml;
content_ws.AddContent(contentHtml);
//AddContent() method is a external method (via webservices)

For example ô is now converted to ô. But i can't reach the code in de Web Service

Thx for help


No you don't need to escape these characters. What stopped you from trying this out yourself?

UPDATE

Based on your further information I'd say it depends on what the Web Service is expecting. It's likely that the Web Service will encode incoming string data. Have you tried this? What are your current results?


Nope. < and > needs no escaping. The only time you might need to escape < and > is when the string is represented as data inside of XML in which case < has to be &lt; and > has to be &gt;.

EDIT:

for asp.net you can use

string a = "<test>abcdef</test>";
string encodedXml = HttpUtility.HtmlEncode(a);


I believe no escape character is needed. Have a look on this MSDN link


Make sure the string is encoded in UTF-16(seems to be the one you are using) before sending!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜