logic for parsing xml