私はXElement
オブジェクトを持っています。このオブジェクトには約120MBのデータが含まれています。 XMLはそれぞれ約20KBの約6000個の要素で構成されています。XElement.ToString()によりSystem.OutOfMemoryExceptionが発生する
XElement.ToString()
私はWebサービスでOuterXmlを返す必要があるので、私はXElement.ToString()
に電話をかけようとしています。
私は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()の代替案を誰にでも提案できますか?あるいは、より大きなメモリ空間を可能にするいくつかのパラメータを設定できますか?
ウェブサービスで120MBのデータを返す必要があります。 – Phill
これは私が考えていたものです。 –
データを圧縮して返します。 – TalentTuner