Using the .Net framework, I need to read XML entity text as raw string values (character entities not expanded) for use in a comparison / merge function. As far as I can tell, there's no way of directly turning off character entity expansion.
I've tried deriving from XmlTextReader and hooking the Read() method, which does intercept reads, but the Value property is read-only and I can't see any way of modifying the incoming text:
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;
}
}
}
Does anyone know how to either disable character entity expansion or updating strings at the point they're read?
Kinda stuck here so thanks in advance for ideas...