I\'m using the XElement object to build some HTML in the code-behind on an ASP.NET page.
I may or may not add some XAttributes to this XElement as I go along, in the
I resolved this by using the HtmlAgilitypack to convert the string of HTML into a hierarchical object.
I then looped through each HTML element in this object and created a nested XElement for each.
There's a little bit of checking that needs done on every element, but it works perfectly and has fewer lines of code than I expected when I started building it.