元素内容大小 [英] Element content size
问题描述
在XML节点中,内容的大小是否有限制?我们可以在单个节点中放入多少数据(以千比特或兆字节为单位)?
In a XML node, is there any limitation on the size of content? How much data (in Kilo Bytes or Mega Bytes) we can put inside a single node?
例如:
string str="1111111111111111111111111111";
XElement elem = new XElement("Root", new XElement("BigData", str));
推荐答案
好
任何.NET字符串的Length属性是一个int值,
int.MaxValue是2147483647 。 E .NET字符串中的ach字符表示为双字节值我想。因此,为了表示内存中最大长度的字符串,你需要
需要4294967294字节的内存,大约是4194304 KB或4096 MB,这几乎是4GB,只能在内存中保存一个最大长度的字符串。
Well the Length property of any .NET string is an int value and int.MaxValue is 2147483647. Each character in a .NET string is represented as a two byte value I think. So to represent a string of the maximum length in memory you would need 4294967294 bytes of memory which is about 4194304 KB or 4096 MB which is nearly 4GB to hold a string of maximum length alone in memory.
一个价值属性XElement也是一个.NET字符串,虽然它可能是一个计算属性,因为它连接所有后代的内容。
LINQ to XML对象模型中的叶节点是XText节点,它们还具有
a值属性,即.NET字符串。一个XElement可以有几个XText子节点,因此如果你有足够的可用内存,你可以将几个具有最大值的XText节点放入你的XElement中。
The Value property of an XElement is also a .NET string although that is likely to be a computed property as it concatenates the contents of all descendants. The leaf nodes in the LINQ to XML object model are XText nodes, they also have a Value property which is .NET string. An XElement can have several XText child nodes so you might be able to put several XText nodes with a maximum Value into your XElement if you have enough memory available.
我在这里尝试简单地构造一个StringBuilder的最大长度字符串导致OutOfMemory异常,因此如果您尝试插入超过int.MaxValue字符的内容,我无法测试XElement的行为。
My attempts here to simply construct a string of maximum length with a StringBuilder result in OutOfMemory exceptions so I can't test how XElement behaves if you try to insert content that exceeds int.MaxValue characters.
这篇关于元素内容大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!