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

4

22

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

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

Undersell answered 26/8, 2009 at 13:41 Comment(0)
T
28

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

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

Tolmach answered 26/8, 2009 at 13:43 Comment(1)
Correct, the XML recommendation doesn't limit the lengths of anything.Corotto
P
10

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.

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

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.

Pipit answered 28/8, 2009 at 16:28 Comment(0)
J
1

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.

Jeri answered 26/8, 2009 at 13:43 Comment(0)
A
1

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:

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.

Arrearage answered 9/9, 2009 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.