How do you export bones relative to parent?
The code snippet you give seems to be correct if you want the transform from the head of the parent bone to the head of the child bone.

How is the translation incorrect? There are supposed to be two translations between these bones, one from the head of the parent to its tail, and (if the child is not connected to the parent) one from the tail of the parent to the head of the child.

In the 2.40 armatures guide, bone.matrix is bone_mat and bone.matrix_local is arm_mat. This is how they relate in python:

# parent head to tail, and parent tail to child head
bone_translation = Matrix.Translation(Vector((0, bone.parent.length, 0)) + bone.head)
# parent armature space matrix, translation, child bone rotation
bone.matrix_local == bone.parent.matrix_local * bone_translation * bone.matrix.to_4x4()