Search code examples
pythondata-analysis

what is a lightweight library to read xml in python?


I need to process some XML files in python. there are lot of libraries to choose from, is there a lightweight one that is efficient? I just need to get an author name from XML ( sample below) . also, I want to open the xml file , read one element/attribute, save the value in a variable or list, and close the file immediately, so that i don't use too much memory. I have lot of these XML files to process.

<?xml version="1.0"?>
<catalog>
   <book id="bk110">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in 
      detail in this deep programmer's reference.</description>
   </book>
 
  
</catalog>

Solution

  • You could use the python native support for xml documentation

    More examples in The ElementTree XML API documentation