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 <
and >
has to be >
.
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!
精彩评论