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);
}
}
}
But it does not resolve the entities in the XML document.
ReplyDeleteIf the DTD not exists, Error is occured on load document. The same problem always.
ReplyDeleteTo Anonymous, here is the VB.NET code that I use to ignore the DTD
ReplyDelete' do not resolve DTD
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.XmlResolver = Nothing
' read xml file
Dim str As XmlReader = XmlTextReader.Create(fileName, settings)
Dim doc As XmlDocument = New XmlDocument()
doc.Load(str)
' remove DOCTYPE tag
If doc.DocumentType IsNot Nothing Then
Dim XDType As XmlDocumentType = doc.DocumentType
doc.RemoveChild(XDType)
End If
It's pretty helpful,i should recommended it to my freinds.
ReplyDeletethanks a lot
solved my issue..thanks
ReplyDeleteAt COEPD we are glad to announce Web Designing Internship Programs (Self sponsored) for professionals who want to have hands on experience. Associations with IT Companies, at present we are providing this program in COEPD Hyderabad premises. We anticipate finest web designing technology covering Photoshop, HTML, CSS, HTML5, CSS3, JavaScript, Boot Strap, and JQuery. We tutor participants to be solution providers and creative engineers. This internship is intelligently dedicated to our enthusiastic and passionate participants mostly acknowledging and appreciating the fact that they are on the path of making a career in Web Designing. This internship is designed to fortify that in addition to gaining the vital theoretical knowledge, the readers gain sufficient hands-on practice and practical know-how to master the essence of Web Designing profession. More than a training institute, COEPD today stands differentiated as a mission to help you "Build your dream career" - COEPD way.
ReplyDeletehttp://www.coepd.com/WebDesigning-Internships.html