Parsing xml tree attributes (file has no elements)
<p>I have been trying to use minidom but have no real preference. For some reason lxml will not install on my machine. </p>

<p>I would like to parse an xml file:</p>

<pre><code>&lt;?xml version="1.
    -&lt;transfer frmt="1" vtl="0" serial_number="E5XX-0822" date="2016-10-03 16:34:53.000" style="startstop"&gt;
        -&lt;plateInfo&gt;
              &lt;plate barcode="E0122326" name="384plate" type="source"/&gt;
              &lt;plate barcode="A1234516" name="1536plateD" type="destination"/&gt;
        &lt;/plateInfo&gt;
        -&lt;printmap total="1387"&gt;
            &lt;w reason="" cf="13" aa="1.779" eo="299.798" tof="32.357" sv="1565.311" ct="1.627" ft="1.649" fc="88.226" memt="0.877" fldu="Percent" fld="DMSO" dy="0" dx="0" region="-1" tz="18989.481" gy="72468.649" gx="55070.768" avt="50" vt="50" vl="3.68" cvl="3.63" t="16:30:47.703" dc="0" dr="0" dn="A1" c="0" r="0" n="A1"/&gt;
            &lt;w reason="" cf="13" aa="1.779" eo="299.798" tof="32.357" sv="1565.311" ct="1.627" ft="1.649" fc="88.226" memt="0.877" fldu="Percent" fld="DMSO" dy="0" dx="0" region="-1" tz="18989.481" gy="72468.649" gx="55070.768" avt="50" vt="50" vl="3.68" cvl="3.63" t="16:30:47.703" dc="0" dr="0" dn="A1" c="1" r="0" n="A2"/&gt;
        &lt;/printmap&gt;
    &lt;/transfer&gt;
</code></pre>

<p>The files do not have any element details, as you can see. All the information is contained in the attributes. In trying to adapt another SO post, I have this - but it seems to be geared more toward elements. I am also failing at a good way to "browse" the xml information, i.e. I would like to say "dir(xml_file)" and have a list of all the methods I can carry out on my tree structure, or see all the attributes. I know this was a lot and potentially different directions, but thank you in advance!</p>

<pre><code>def parse(files):
    for xml_file in files:
        xmldoc = minidom.parse(xml_file)
        transfer = xmldoc.getElementsByTagName('transfer')[0]
        plateInfo = transfer.getElementsByTagName('plateInfo')[0]
</code></pre>

<p>With minidom you can access the attributes of a particular element using the method attributes which can then be treated as dictionary; this example iterates and print the attributes of the element transfer[0]:</p>

<pre><code>from xml.dom.minidom import parse, parseString
xml_file='''&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;transfer frmt="1" vtl="0" serial_number="E5XX-0822" date="2016-10-03 16:34:53.000" style="startstop"&gt;
        &lt;plateInfo&gt;
              &lt;plate barcode="E0122326" name="384plate" type="source"/&gt;
              &lt;plate barcode="A1234516" name="1536plateD" type="destination"/&gt;
        &lt;/plateInfo&gt;
        &lt;printmap total="1387"&gt;
            &lt;w reason="" cf="13" aa="1.779" eo="299.798" tof="32.357" sv="1565.311" ct="1.627" ft="1.649" fc="88.226" memt="0.877" fldu="Percent" fld="DMSO" dy="0" dx="0" region="-1" tz="18989.481" gy="72468.649" gx="55070.768" avt="50" vt="50" vl="3.68" cvl="3.63" t="16:30:47.703" dc="0" dr="0" dn="A1" c="0" r="0" n="A1"/&gt;
            &lt;w reason="" cf="13" aa="1.779" eo="299.798" tof="32.357" sv="1565.311" ct="1.627" ft="1.649" fc="88.226" memt="0.877" fldu="Percent" fld="DMSO" dy="0" dx="0" region="-1" tz="18989.481" gy="72468.649" gx="55070.768" avt="50" vt="50" vl="3.68" cvl="3.63" t="16:30:47.703" dc="0" dr="0" dn="A1" c="1" r="0" n="A2"/&gt;
        &lt;/printmap&gt;
    &lt;/transfer&gt;'''
xmldoc = parseString(xml_file)
transfer = xmldoc.getElementsByTagName('transfer')
attlist= transfer[0].attributes.keys()
for a in attlist:
    print transfer[0].attributes[a].name,transfer[0].attributes[a].value
</code></pre>

<p>you can find more information here:</p>

<p><a href="http://www.diveintopython.net/xml_processing/attributes.html" rel="nofollow">http://www.diveintopython.net/xml_processing/attributes.html</a></p>

python xml minidom