title: How can I read the attributes of a root node without getting them by name?
body: <p>Suppose, I have the follwing XML file:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;library attrib1=&quot;att11&quot; attrib2=&quot;att22&quot;&gt;
      library-text
      &lt;book isbn=&quot;1111111111&quot;&gt;
          &lt;title lang=&quot;en&quot;&gt;T1 T1 T1 T1 T1&lt;/title&gt;
          &lt;date&gt;2001&lt;/date&gt;
          &lt;author&gt;A1 A1 A1 A1 A1&lt;/author&gt;     
          &lt;price&gt;10.00&lt;/price&gt;
      &lt;/book&gt;
      &lt;book isbn=&quot;2222222222&quot;&gt;
          &lt;title lang=&quot;en&quot;&gt;T2 T2 T2 T2 T2&lt;/title&gt;
          &lt;date&gt;2002&lt;/date&gt;
          &lt;author&gt;A2 A2 A2 A2 A2&lt;/author&gt;     
          &lt;price&gt;20.00&lt;/price&gt;
      &lt;/book&gt;
      &lt;book isbn=&quot;3333333333&quot;&gt;
          &lt;title lang=&quot;en&quot;&gt;T3 T3 T3 T3&lt;/title&gt;
          &lt;date&gt;2003&lt;/date&gt;
          &lt;author&gt;A3 A3 A3 A3 A3y&lt;/author&gt;        
          &lt;price&gt;30.00&lt;/price&gt;
      &lt;/book&gt;
  &lt;/library&gt;
  </code></pre>
  <p>I want to programmatically print the names of the attributes and their values of the root-node.</p>
  <p>How can I do that?</p>
  <p>I tried the following code:</p>
  <pre><code>import xml.dom.minidom as minidom
  
  xml_fname = &quot;library.xml&quot;
  
  dom = minidom.parse(xml_fname) 
  
  print(dom.firstChild.tagName)
  print(dom.firstChild.attributes[0].value)
  </code></pre>
  <p>It gives the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;main.py&quot;, line 8, in &lt;module&gt;
      print(dom.firstChild.attributes[0].value)
    File &quot;/usr/lib/python3.8/xml/dom/minidom.py&quot;, line 552, in __getitem__
      return self._attrs[attname_or_tuple]
  KeyError: 0
  </code></pre>