Maybe this and handling the case of "attribute begins with a '/'" could be split out into a "normalize_and_validate" method so they're not inside this main loop?