これは、XmlTextReader (および XmlValidatingReader) クラスの単純なオプションであることがわかります - 「EntityHandling」。
あなたの問題の簡単なデモ:
System.Xml.XmlTextReader textReader = new System.Xml.XmlTextReader("testin.xml");
textReader.EntityHandling = System.Xml.EntityHandling.ExpandEntities;
System.Xml.XmlDocument outputDoc = new System.Xml.XmlDocument();
outputDoc.Load(textReader);
System.Xml.XmlDocumentType docTypeIfPresent = outputDoc.DocumentType;
if (docTypeIfPresent != null)
outputDoc.RemoveChild(docTypeIfPresent);
outputDoc.Save("testout.html");
textReader.Close();
また、ドキュメントをメモリにロードする必要がない場合は、同等のストリーミング:
System.Xml.XmlTextReader textReader = new System.Xml.XmlTextReader("testin.xml");
textReader.EntityHandling = System.Xml.EntityHandling.ExpandEntities;
System.Xml.XmlTextWriter textWriter = new System.Xml.XmlTextWriter("testout.html", System.Text.Encoding.UTF8);
while (textReader.Read())
{
if (textReader.NodeType != System.Xml.XmlNodeType.DocumentType)
textWriter.WriteNode(textReader, false);
else
textReader.Skip();
}
textWriter.Close();