使用 .Net 框架,我需要将 XML 实体文本作为原始字符串值(未扩展的字符实体)读取,以用于比较/合并功能。据我所知,没有办法直接关闭角色实体扩展。
我尝试从 XmlTextReader 派生并挂钩 Read() 方法,该方法会拦截读取,但 Value 属性是只读的,我看不到任何修改传入文本的方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace blah {
class XmlRawTextReader : XmlTextReader {
public XmlRawTextReader(string fileName) : base(fileName) { }
public override bool Read() {
bool result = base.Read();
if (result == true && base.HasValue && base.NodeType == XmlNodeType.Text) {
string s = this.Value;
//this.Value = @"new value"; // does not work - read-only
}
return result;
}
}
}
有谁知道如何禁用字符实体扩展或在读取字符串时更新字符串?
有点卡在这里所以提前感谢您的想法...