I haven't written a skeleton exporter in a long time so this might be a little off.
For each bone you want to write its local position and rotation releative to
parent. The ROOT bone will be in world_space. For every CHILD bone you want to
take its transform and multiply against the inverse of its parents transform.
That will give you its local transform.
--------------------------------
trans = bn.transform
if ( bn.parent != undefined ) then
trans = trans * (inverse (bn.parent.transform))
t = trans.translationpart // point3
r = trans.rotationpart; // quat
--------------------------------
For animations I think you want to write the transform difference from the last frame.
Side Note:
You should look at
Cal3D.
It's an easy to use skeletal animation library. It comes with maya/max exporters.
It's opensource so it is good for reference even if you don't end up using it.