我在较大的XML文档中创建了几个XmlElements。将&符号添加到XmlElement中
XmlElement thisElement = xmlSearchParameters.CreateElement("value");
thisElement.InnerXml = this.searchParameters[key];
这非常适用于大多数情况,但如果searchParameters [关键]的值恰好包括&符号,我得到以下两个错误之一:发生
意外的文件结尾。行1,位置1. - 如果值仅为&
解析EntityName时发生错误。第1行,第7位。 - 如果值包含&与其他文字混合。
在XmlElement中包含&和任何其他特殊符号的首选方式是什么?我怀疑必须有更好的方法,而不是用别的东西替换&(某种XmlFormat方法???)。
感谢您的提示。过去我没有使用过XmlElement,而这正是我开始编写代码时的设置方式。更改为使用InnerText解决了我的问题。 – Kris 2009-07-30 17:44:48