我有一個XElement
對象,其中包含約120MB的數據。 XML由約6000個元素組成,每個元素大約20kb。XElement.ToString()導致System.OutOfMemoryException
我想撥打XElement.ToString()
,因爲我需要在Web服務中返回OuterXml。
我得到一個System.OutOfMemoryException
。
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
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, Int32 startIndex, Int32 charCount)
at System.IO.StringWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.WriteString(String text)
at System.Xml.XmlEncodedRawTextWriterIndent.WriteString(String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)
at System.Xml.XmlWriter.WriteAttributeString(String prefix, String localName, String ns, String value)
at System.Xml.Linq.ElementWriter.WriteStartElement(XElement e)
at System.Xml.Linq.ElementWriter.WriteElement(XElement e)
at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
at System.Xml.Linq.XNode.GetXmlString(SaveOptions o)
at System.Xml.Linq.XNode.ToString()
我在XmlDocument
相同的數據,並可以調用XmlDocument.OuterXml
沒有問題。我也可以撥打XElement.Save()
將XML保存到一個沒有問題的文件中。
任何人都可以提出一個替代XElement.ToString(),這將是更少的內存密集?或者,我可以設置一些參數,以允許更大的內存空間?
您需要在Web服務返回數據的120MB ... – Phill 2010-11-25 09:36:02
這就是我在想... – 2010-11-25 09:39:12