Windows Phone Developers

Showing posts with label Remove DOCTYPE declaration from XML Files using C#. Show all posts
Showing posts with label Remove DOCTYPE declaration from XML Files using C#. Show all posts

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)

{

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);

}

}

}

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