For a instance we have some IHttpHandler. where we have two valiables: XmlElement xmlResponse - contains a really big XML. HttpContext context - current HttpContext.
The simple solution:
context.Response.Write(xmlResponse.OwnerDocument.OuterXml);
but when a XML is really big we can get OutOfMemoryException at that line. A call stack will look like:
at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
at System.Text.StringBuilder.Append(Char value)
at System.IO.StringWriter.Write(Char value)
at System.Xml.XmlTextWriter.InternalWriteEndElement(Boolean longFormat)
at System.Xml.XmlTextWriter.WriteFullEndElement()
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw)
at System.Xml.XmlDocument.WriteTo(XmlWriter w)
at System.Xml.XmlNode.get_OuterXml()
I'd write some such code:
HttpWriter writer = new HttpWriter(context.Response);
XmlTextWriter xmlWriter = new XmlTextWriter(writer);
xmlResponse.OwnerDocument.WriteTo(xmlWriter);
But a problem is that HttpWriter's constructor is internal! HttpContext uses HttpWriter internally in Write methods.
What do workarrounds exist (except creating HttpWriter through reflection) ?