Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 927
G33kKahuna Avatar asked Aug 26 '09 13:08

G33kKahuna


People also ask

How many attributes are there in XML?

Attribute Types: There are three types of attributes described below: String types Attribute: This type of attribute takes any string literal as a value.

Can XML attribute have multiple values?

attributes cannot contain multiple values (elements can) attributes cannot contain tree structures (elements can) attributes are not easily expandable (for future changes)


2 Answers

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.

like image 78
Justin Niessner Avatar answered Sep 22 '22 14:09

Justin Niessner


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.

like image 30
JK. Avatar answered Sep 23 '22 14:09

JK.