is there a way to count how many xrecords are in a document?
Probably, but it's going to be: Go through each dictionary (including all attached to the namedobjdict and each entity in the entire database), then use dictnext to find each XRecord and inside each sub-dictionary (or any other such container entity). So it can be an extremely inefficient idea.