Significantly refactored the XML parsing code.