我的应用程序从外部试图XML保存到磁盘(当它进入XmlWriter
)为什么.NET XML API不能保护我不受空字符的影响?
System.ArgumentException : '.', hexadecimal value 0x00, is an invalid character.
时收到字符串和构建XML文档
string fromOutside = "\0";
XAttribute a = new XAttribute(fromOutside);
当属性值包含空字符,然后我得到异常
即使SecurityElement
类不利于
Assert.IsFalse(SecurityElement.IsValidAttributeValue("\0"));
什么是最好的从字符串构造XML文档的方式,可能包含像空字符等无效字符?
所以在我的情况下,唯一的办法就是分析字符串并删除空人物,不是吗? :-( –
不,你也可以Base64编码字符串:'Convert.ToBase64String(Encoding.UTF8.GetBytes(fromOutside))' –
Base64对我来说不是一个选项,因为我必须保持字符串在结果中可读XML 。字符串的例子可以是“\ 0My \ 0 fancy val \ 0ue \ 0 \ 0 \ 0”。 –