Refactor mdx_caption, using ElementTree more properly