Skip to content

Instantly share code, notes, and snippets.

@bozhink
Created October 24, 2016 09:40
Show Gist options
  • Save bozhink/b0ffa979bfacda481bf1c23302fcfdb0 to your computer and use it in GitHub Desktop.
Save bozhink/b0ffa979bfacda481bf1c23302fcfdb0 to your computer and use it in GitHub Desktop.
Extension method to transform XDocument to XmlDocument
/// <summary>
/// Converts XDocument to XmlDocument.
/// Original source: <see cref="http://stackoverflow.com/questions/1508572/converting-xdocument-to-xmldocument-and-vice-versa"/>
/// </summary>
/// <param name="document">XDocument instance to be converted.</param>
/// <returns></returns>
public static XmlDocument XToXmlDocument(this XDocument document)
{
XmlDocument xmlDocument = new XmlDocument();
using (XmlReader xmlReader = document.CreateReader())
{
xmlDocument.Load(xmlReader);
}
return xmlDocument;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment