Created
October 24, 2016 09:38
-
-
Save bozhink/5d40fde992c0d33f3ee111031ec83c69 to your computer and use it in GitHub Desktop.
Extension method to transform XmlDocument to XDocument
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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