TL;DR: There are 2 indices. Try to keep them identical to avoid confusion. I've developed an Add-On which might help you: https://www.bschwb.com/add-ons/pen-manager/ But it depends on what you actually want to achieve. More explanation below.
I had a look into your problem in more detail and I think I've figured it out (but still take it with a grain of salt):
There are two different indices!
- One is displayed in the Attribute Manager under the Column '#'. This corresponds to the "physical" ordering in the .xml file you were describing.
- The other one is an internal Index which in the xml is placed in the tag '<Index>'
A small demonstration that hopefully illustrates the point a bit:
1. Export a pen set via the Attribute Manger to an .xml file
2. Reorder the first pen to the 5th 'physical' place but keep the <Index>1</Index> tag.
3. Import the pen set again via the Attribute Manager
4. Using the pen e.g. in the "Wall Settings" shows the two different indices (See annotated screenshot)
To avoid confusion, I would keep the two indices identical all the time. So if you manually reorder the list, I would also change the <Index> tag accordingly.
What my 'Pen-Manager' Add-On does:
When copying one pen to a different pen it keeps both indices of the target pen but changes the Color, Width and Description of the Target Pen!
EXTRA NOTE for Add-On developers:
In the API_PenType the field 'index' stores the internal index, but elements seem to store the 'physical' index (e.g. element.wall.contPen).
I hope this helps!