I'm converting some code that currently uses an XmlWriter
to create a document to instead return an XElement
of the content.
So far, I'm enjoying structuring the code in a way that mimics the structure of the document, but there is content that was written using XmlWriter.WriteRaw
to avoid re-xmlizing the xml. I can't find any equivalent in the System.Xml.Linq
namespace. Does one exist?
Caveat: only applicable if your purpose is simply for rendering the XML string, and you're sure the contents are already XML
Since
XElement.Parse
"re-xmlizes" the already existing XML, you could set the contents to a 'placeholder' value (as suggested here) and replace it in the rendered output:Note that this won't guarantee 'pretty formatting' unless
child
already has it.Testing this in LinqPad seems to indicate that 'Replacing' is faster than using
Parse
:where
Vs
is a wrapper function for running each delegate 10000 times inside a stopwatch.XElement.Parse()
should do the trick.For example: