def shortenIDs(doc, unprotectedElements=None):
 num = 0
 identifiedElements = findElementsWithId(doc.documentElement)
 if (unprotectedElements is None):
  unprotectedElements = identifiedElements
 referencedIDs = findReferencedElements(doc.documentElement)
 idList = [(referencedIDs[rid][0], rid) for rid in referencedIDs if (rid in unprotectedElements)]
 idList.sort(reverse=True)
 idList = [rid for (count, rid) in idList]
 curIdNum = 1
 for rid in idList:
  curId = intToID(curIdNum)
  if (curId != rid):
   while (curId in identifiedElements):
    curIdNum += 1
    curId = intToID(curIdNum)
   num += renameID(doc, rid, curId, identifiedElements, referencedIDs)
  curIdNum += 1
 return num

def shortenIDs ( doc , unprotectedElements = None ) : num = 0 identifiedElements = findElementsWithId ( doc . documentElement ) if ( unprotectedElements is None ) : unprotectedElements = identifiedElements referencedIDs = findReferencedElements ( doc . documentElement ) idList = [ ( referencedIDs [ rid ] [ 0 ] , rid ) for rid in referencedIDs if ( rid in unprotectedElements ) ] idList . sort ( reverse = True ) idList = [ rid for ( count , rid ) in idList ] curIdNum = 1 for rid in idList : curId = intToID ( curIdNum ) if ( curId != rid ) : while ( curId in identifiedElements ) : curIdNum += 1 curId = intToID ( curIdNum ) num += renameID ( doc , rid , curId , identifiedElements , referencedIDs ) curIdNum += 1 return num
shortens id names used in the document .