Search code examples
c#xmllinq-to-xmldocumentfragment

XmlDocumentFragment equivalent in LINQ to XML?


I am unable to find something like XDocumentFragment. Is there an equivalent of XmlDocumentFragment in LINQ to XML?

I know that I can keep nodes in a collection. But how to conveniently serialize a bunch of various nodes to string, like this:

new XDocumentFragment(myNodes).ToString()

Solution

  • You can simply concatenate string representation of nodes:

    var xml = String.Concat(myNodes);