How to parse XML and count instances of a particular node attribute?
Asked 07 September, 2021
Viewed 1.1K times
  • 63
Votes

I have many rows in a database that contains XML and I'm trying to write a Python script to count instances of a particular node attribute.

My tree looks like:

<foo>
   <bar>
      <type foobar="1"/>
      <type foobar="2"/>
   </bar>
</foo>

How can I access the attributes "1" and "2" in the XML using Python?

18 Answer