Skip to content

Instantly share code, notes, and snippets.

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