开发者

Cant get correct result from XmlDocument Load-method because of the characters

EDIT: This was solved by changing how the webse开发者_JAVA百科rvice interprates GET-requests (to UTF-8).

I send a string to an URL that returns an XML to me. But the resulting XML is not correct if I send special characters, such as å, ä, ö. And I cant get it to work.

 string name= "abc def åäö";
//name= Uri.EscapeUriString(address); - i also tried this but it messes up the åäö chars in the resulting xml
string uri = "http://blablabla&address=" + name+ "&outputFormat=xml";

System.Xml.XmlDocument x = new System.Xml.XmlDocument();
x.Load(uri);
XmlElement root = x.DocumentElement;
foreach (XmlNode node in root.ChildNodes)
{
     XmlAttribute attr = (XmlAttribute)node.Attributes.GetNamedItem("name");
     System.Windows.Forms.MessageBox.Show(attr.Value);
}


I believe what you are doing is correct. You should end up with the characters encoded as pairs of hex digits, each preceded by a percentage symbol, e.g. å becomes %c3%a5. The web server/application server should transparently decode these back to the corresponding characters.

Also see HttpUtility.UrlEncodeUnicode(string), which will uses an alternative encoding, although I'm not sure that this will be handled by all web servers.


I don't know if this helps, but remember that attr.Value is going to escape Xml-type escaping. That doesn't seem like it could be the problem, though. Instead of checking attr.Value, check node.OuterXml to see if that matches your expectations.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜