How to remove Document Type Definition (DTD) declarations from XML Files using C#
XMLSchema is fast replacing DTD. If you have old XML files that link to DTD, you might want to remove the Doctype declarations. The following code should help you in that
private static void Remove_DTD_From_XML(String sXMLFile)
{
try
{
XmlDocument XDoc = new XmlDocument();
XDoc.Load(sXMLFile);
XmlDocumentType XDType = XDoc.DocumentType;
XDoc.RemoveChild(XDType);
XDoc.Save(sXMLFile + ".changed");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}