Skip to content Skip to sidebar Skip to footer

What Is The One Line Max Length Limit In Xml Files?

Recently I've faced an issue related to max line (string) length limit in a path attribute of vector xml. In my case 51k chars appears to be an overlimit while 29k is OK. Anyway,

Solution 1:

My guess reading your question was that the limit would be somewhere between 29k and 51k but clipped to a logical number

I might have found the answer by testing it. As you said, a char is stored on two bytes. So 29k char would be 58k bytes and 51k would be 102k bytes. The "logical" limit would be 65536 as it is 2^16. so the limit in char is 2^16 / 2 or 2^15 which is 32768

I tested to put strings in my string.xml (basically a long line of 'a')

<stringname="length_test32000">(32 000 a)</string><stringname="length_test32767">(32 767 a)</string><stringname="length_test32768">(32 768 a)</string><stringname="length_test32769">(32 769 a)</string><stringname="length_test33000">(33 000 a)</string>

Then i tried to log their size :

String test32k = getString(R.string.length_test32000);

String test32k767 = getString(R.string.length_test32767);
String test32k768 = getString(R.string.length_test32768);
String test32k769 = getString(R.string.length_test32769);

String test33k = getString(R.string.length_test33000);

Log.i("tag", "32000 : "+test32k.length());
Log.i("tag", "32767 : "+test32k767.length());
Log.i("tag", "32768 : "+test32k768.length());
Log.i("tag", "32769 : "+test32k769.length());
Log.i("tag", "33000 : "+test33k.length());

Here are the results :

I/tag: 32000 : 32000
I/tag: 32767 : 32767
I/tag: 32768 : 16
I/tag: 32769 : 16
I/tag: 33000 : 16

From 32768 it seems to be truncated so i log what was inside

Log.i("tag", "32768 : "+test32k768.length() + " content : " + test32k768);

And the result is :

I/tag: 32768 : 16 content : STRING_TOO_LARGE

The maximum char seems to be 32767 (2^15 - 1) characters. I didn't find any official doc that say that, but it is what i found while testing

Post a Comment for "What Is The One Line Max Length Limit In Xml Files?"