Exporting weight and bone elements to a text file
While the answer is in Blender's API docs, the relationships aren't clearly spelt out so you need to "get" some of the relationships to know how it fits together.

An armature can get confusing, there are EditBones that define the armature that you see in edit mode. Then you have PoseBones that are used when posing the bones in an animation.

You access EditBones through bpy.data.armatures['Armature'].edit_bones or while the armature is in edit mode with object.data.edit_bones, while you will find PoseBones in object.pose.bones.

While an EditBone does have a matrix property that combines the location and rotation of the bone, it relies mostly on the head, tail and roll properties of each bone and doesn't keep any rotation properties. The PoseBones use the head as the origin and then the rotation_mode to determine whether the rotation_euler, rotation_axis_angle or the rotation_quaternion property is used.

Both EditBones and PoseBones have a children property to list any children the bone may have.

An object has a list of it's vertex_groups and each vertex group has an index number.

A mesh object's data includes a list of it's vertices and each of these vertices has a groups property that lists the groups that the vertex is associated with. This list contains the group index (which matches the vertex group index above) and the weight used for each group. The group weight is the same value you edit using weight painting.

When an armature deforms a mesh it finds vertices that use a group with the same name as the bone and uses the weight to define how much to influence the vertex.

So while looping through the armature bones, using the bone name you can get the vertex group index for the bone, then get the vertices it influences.

import bpy

arm = bpy.data.objects['Armature']
obj = bpy.data.objects['Cube']

obj_verts = obj.data.vertices
obj_group_names = [g.name for g in obj.vertex_groups]

for bone in arm.pose.bones:
    if bone.name not in obj_group_names:
        continue

    gidx = obj.vertex_groups[bone.name].index

    bone_verts = [v for v in obj_verts if gidx in [g.group for g in v.groups]]

    for v in bone_verts:
        w = v.groups[gidx].weight
        print('Vertex',v.index,'has a weight of',w,'for bone',bone.name)