Created
July 20, 2012 12:11
-
-
Save rarous/3150395 to your computer and use it in GitHub Desktop.
Convert XElement to XmlElement
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
using System.Xml; | |
using System.Xml.Linq; | |
public static class XElementExtensions | |
{ | |
public static XmlElement ToXmlElement(this XElement el) | |
{ | |
var doc = new XmlDocument(); | |
doc.Load(el.CreateReader()); | |
return doc.DocumentElement; | |
} | |
} |
๐ ๐ ๐ ๐ ๐
Thanks a lot!! It's very helpful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice; found this while working in a legacy code area. For converting to the middle of an existing XmlDocument instance, you can make this a bit messier like:
The returned element could then be appended as a child of any element in
ownerDocument
.