public XmlElement ToXmlElement (this string xml)
{
XmlDocumentFragment frag = new XmlDocument().CreateDocumentFragment();
frag.InnerXml = xml;
return frag.FirstChild as XmlElement;
}
The problem with this is you have to assume the string you are passing in is well-f0rmed XML.
I love extension methods - best thing since code-behind.
ReplyDeleteI've worked with XML a lot but generally every piece of XML was converted to an XmlDocument.
Depends what the bigger picture is I guess.