如何在Xml中读写¬ [英] How to read and write ¬ in Xml
问题描述
我正在将一些注册表信息写入XML文件. regkey中有一个¬符号正在作为字符串的值生成. 当我写XML时,我会得到.当我尝试将其读回时,出现错误.有什么方法可以克服这个问题,我该如何进行?
I am writing some registry information into a XML file. There is ¬ symbol that is getting generated as a value for a string in regkey. When I write into XML I am geting and when I try read it back, I am getting an error. Is there a way to overcome this, how can I proceed?
阅读时出现错误:
> System.InvalidOperationException was unhandled
> Message="There is an error in XML document (235, 28)."
从文件读取:
public diagnostics readregkey(diagnostics diagnostics, string filename)
{
diagnostics dia = null;
using (System.IO.StreamReader sr =
new System.IO.StreamReader(filename, Encoding.Unicode))
{
System.Xml.Serialization.XmlSerializer x =
new System.Xml.Serialization.XmlSerializer(typeof(diagnostics));
dia = x.Deserialize(sr) as diagnostics;
}
return dia;
}
写入文件:
public static void WriteRegKey(diagnostics diagnostics, string filename)
{
diagnostic.regKeys.Add(key(Registry.LocalMachine, sKeyGravitas));
diagnostic.regKeys.Add(key(Registry.CurrentUser, sKeyGravitas));
using (System.IO.StreamWriter sw =
new System.IO.StreamWriter(filename,false, Encoding.Unicode))
{
System.Xml.Serialization.XmlSerializer x =
new System.Xml.Serialization.XmlSerializer(typeof(diagnostics));
x.Serialize(sw, diagnostics);
}
}
推荐答案
您可以使用WriteRaw方法,该方法允许您手动写出原始标记.这种方法可以防止特殊字符被转义.
You can use the WriteRaw method which allows you to write out raw markup manually. This method prevents special characters from being escaped.
您可以在此处找到文档: http://msdn.microsoft.com/zh-CN/library/4zhk8s1x%28v=vs.71%29.aspx
You can find documentation here : http://msdn.microsoft.com/en-us/library/4zhk8s1x%28v=vs.71%29.aspx
这篇关于如何在Xml中读写¬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!