Problem is not xml, json or any other non linear data structure. It's trying to use shell to manipulate data that it's not intended to.
Shell will always have problems with handling bloated/overheaded data structures. In these situations using intermediary higher level languages would help.
PS: I'm sorry my first post is unintentionally against new rule. I just realized.