Added write_xml() helper that writes the given tree-ish structure into the current xml writer. Improved get_contextid() so that it can use indices for searching data. Added set_stash() and get_stash() helper methods.