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

29,126

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Share:
29,126
G33kKahuna
Author by

G33kKahuna

Updated on November 16, 2020

Comments

  • G33kKahuna
    G33kKahuna over 3 years

    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.

  • Richard
    Richard over 14 years
    Correct, the XML recommendation doesn't limit the lengths of anything.