I know there is no direct method of doing it but still..
Can we convert XElement
element into XmlNode
.
Options like InnerText
and InnerXml
are XmlNode
specific.
so,if i want to use these options, what can be done to convert XElement
into XmlNode
and vice versa.
Here is converting from string to XElement to XmlNode and back to XElement. ToString() on XElement is similar to OuterXml on XmlNode.
I think the shortest way is following:
That's all! Convert to C# is trivial.
I use the following extension methods, they seem to be quite common:
Based on BrokenGlass's answer, if you wish to embed the XmlNode to an XmlDocument, than use:
Note: if you try to insert into a document a node, that is created by a different document, than it will throw an exception: "The node to be inserted is from a different document context."
There are ways to get InnerXml from XElement - see Best way to get InnerXml of an XElement?