refactor xml handling to DRY things up a bit