Extracted method for parsing XML document