我有一个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