Thanks to [RobertL](https://unix.stackexchange.com/users/139893/robertl) for this [answer](https://unix.stackexchange.com/a/249258/139072).
I also came up with a combination of `grep/awk/sed` to achieve the same but it is slower obviously. Just wanted to put it out there.
egrep -w ""\<SOURCE"|"SOURCEFIELD.*XYZ.*"" sample.xml|grep -B1 XYZ|grep -w SOURCE|\
> awk -F" NAME =" '{print $2}'|awk '{print $1}'|sed 's/"//g'