XML 属性中允许的最大字符数是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1334776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:42:53  来源:igfitidea点击:

What is the max number of characters allowed in an XML attribute?

xmlxml-attribute

提问by G33kKahuna

Is there a standard for the maximum number of characters allowed in an XML attribute?

XML 属性中允许的最大字符数是否有标准?

I tried researching W3C consortium and couldn't find anything on the character limit aside from some notes on escaping special characters.

我尝试研究 W3C 联盟,除了一些关于转义特殊字符的注释外,找不到任何关于字符限制的内容。

回答by Justin Niessner

I don't believe there is a character limit per the XML specification, but the Best Practice is to keep attribute values short.

我不相信每个 XML 规范都有字符限制,但最佳实践是保持属性值简短。

If an attribute value grows long...chances are that it should be an element of its own rather than an attribute on another element.

如果一个属性值增长很长时间...很有可能它应该是它自己的一个元素,而不是另一个元素上的一个属性。

回答by JK.

There is no maximum character length for an attribute.

属性没有最大字符长度。

The spot where you could run into issues is the point where you are reading the xml file using another language.

您可能遇到问题的地方是您使用另一种语言读取 xml 文件的地方。

The language you use to manipulate the xml file will determine your limitations.

您用于操作 xml 文件的语言将决定您的局限性。

For instance, if you plan on reading the information into a String, you should limit yourself to the maximum number of characters that can be held in a string in the language you are using.

例如,如果您打算将信息读入一个字符串,您应该限制自己在您使用的语言中的字符串中可以包含的最大字符数。

Additionally, as others have said, you are probably not following standard name conventions if this is a problem. I would suggest that, if you have a large amount of text to store, it should be the value of an element, not an attribute.

此外,正如其他人所说,如果这是一个问题,您可能没有遵循标准名称约定。我建议,如果你有大量的文本要存储,它应该是一个元素的值,而不是一个属性。

回答by peter.murray.rust

An attribute is composed or a name and a value. The value can be of any length including zero and can contain any valid XML characters, depending on the encoding. The name may or may not be qualified with a namespace; if so if will have a prefix of at least one character. The shortest attributes are therefore:

属性由名称和值组成。该值可以是包括零在内的任何长度,并且可以包含任何有效的 XML 字符,具体取决于编码。该名称可能会或可能不会被命名空间限定;如果是这样,if 将具有至少一个字符的前缀。因此,最短的属性是:

a=''
b:a=''

The attribute value will be normalised by conforming XML parsers so that whitespaces such as newlines will be normalised to single spaces.

属性值将通过符合 XML 解析器的规范化,以便将换行符等空格规范化为单个空格。

回答by Michael Krelin - hacker

I don't think there are standard limitations, but any particular implementation may be limited in its capabilities, so I'd try to keep the size sane.

我认为没有标准限制,但任何特定实现的功能都可能受到限制,因此我会尽量保持大小合理。