Background
I'm reading and writing an XML document using reader and writer, with filtering logic in between the read and write operations to determine which parts read should be written back out (effectively it strips some tags out) ...
My choice of implementation currently is the following using: XmlNodeReader, XmlWriter and XmlNodeType
using System.Xml;
// Read every node
using (XmlNodeReader reader = new XmlNodeReader(xmlFragment)) {
// But write out only nodes I want
using (XmlWriter writer = XmlTextWriter.Create(sb, writerSettings)) {
while (reader.Read()) {
//... with filtering logic here to choose what is to be written.
// I do want to write out all entity references
if (XmlNodeType.EntityReference == reader.NodeType)
; // but how do I do that here?
}
}
}
Problem
When I encounter an entity reference with the reader I get an empty string "" in reader.Value
however it's really an
value in the XML source that has been encountered. So it's detected, but not available for me to have.
Apparently a Speciality or Edge Case:
I found the following MSDN article that indicates entity references are somewhat special while parsing, but I have been unable to use it toward a working solution. It seems sparse on details - I would prefer there be a code sample to supplement it.