'Parse XML with a specific parent tag

<?xml version="1.0" encoding="utf-8"?>
  <ReturnHeader>
    <Bob>
      <Age>39</Age>
      <PhoneNum>2222</PhoneNum>
    </Bob>
    <John>
      <Age>70</Age>
      <PhoneNum>4444</PhoneNum>
    </John>
  </ReturnHeader>

From the above XML, I'm trying to get only the phone of Bob. (i.e., when Bob is 'True).

I need the following output:

PhoneNum 2222

I tried lxml with Xpath, but no luck. Any help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source