Windows Phone Developers

Tuesday, December 16, 2008

Remove DOCTYPE declaration from XML Files using C#

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)




XmlDocument XDoc = new XmlDocument();


XmlDocumentType XDType = XDoc.DocumentType;


XDoc.Save(sXMLFile + ".changed");


catch (Exception ex)






Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon


  1. But it does not resolve the entities in the XML document.

  2. If the DTD not exists, Error is occured on load document. The same problem always.

  3. To Anonymous, here is the VB.NET code that I use to ignore the DTD

    ' 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()

    ' remove DOCTYPE tag
    If doc.DocumentType IsNot Nothing Then
    Dim XDType As XmlDocumentType = doc.DocumentType
    End If

  4. It's pretty helpful,i should recommended it to my freinds.
    thanks a lot

  5. solved my issue..thanks

  6. At 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.