Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert XmlNode to XNode?

Anyone know off the top of their heads how to convert a System.Xml.XmlNode to System.Xml.Linq.XNode?

like image 642
David Avatar asked Oct 23 '08 20:10

David


2 Answers

I've never tried, but my first thought would be something like:

XmlNode myNode;
XNode translatedNode = XDocument.Parse(myNode.OuterXml);
like image 131
Chris Shaffer Avatar answered Dec 11 '22 07:12

Chris Shaffer


Eric White's blog is the place to be for cool XML/XLINQ conversions and such. I know this question pre-date's the post but I found it while looking at some other Q, so maybe people still come across this a fair amount. His blog has plenty of optimized LINQ, like I suspect the .Parse() call for the origional responce is non-optimal, well in-fact I know it is not.

Parse is going to require that the XML be loaded up in one shot, Eric used extension methods which process the XML conversion with XmlReader/Writer's. Those methods are able to stream the input, so if your XML is of any substantional size, you have to use them.

like image 25
RandomNickName42 Avatar answered Dec 11 '22 08:12

RandomNickName42