So, for reference, the issue is not that this is broken, rather that it is a bit misspecified: <withinid/> was created for an ID reference to the nearest ancestor, whereas the element's ID was specified within <id/> in the message content.
(And yes, I am using the word "specified" loosely, as in "how the code works (and how I thought about it when I wrote the code)".)
Not entirely true, in case of <para id='paraid'>this is a error</para> it wouldn't be 'paraid'.
It's more <idOfParentOfElementWithError> then <withinid>.
So, for reference, the issue is not that this is broken, rather that it is a bit misspecified:
<withinid/>
was created for an ID reference to the nearest ancestor, whereas the element's ID was specified within<id/>
in the message content. (And yes, I am using the word "specified" loosely, as in "how the code works (and how I thought about it when I wrote the code)".)