title: Parsing word doc XML using lxml in Python 3
body: <p>I have some XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="true"?&gt;
  &lt;w:document mc:Ignorable="w14 w15 w16se w16cid wp14" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"&gt;
     &lt;w:body&gt;
       &lt;w:sectPr w:rsidRPr="0019552A" w:rsidR="0019552A"&gt;
         &lt;w:pgSz w:w="12240" w:h="15840"/&gt;
         &lt;w:pgMar w:gutter="0" w:footer="720" w:header="720" 
          w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/&gt;
         &lt;w:cols w:space="720"/&gt; 
         &lt;w:docGrid w:linePitch="360"/&gt;
       &lt;/w:sectPr&gt;
     &lt;/w:body&gt;
  &lt;/w:document&gt;
  </code></pre>
  
  <p>I want to grab the page margin and page size data (w:w='12240', w:gutter='0', etc.). Using lxml, I managed to grab the element containing the pgMar data:</p>
  
  <pre><code>from lxml import etree
  root = etree.fromstring(xml)
  ns = {'w': root.nsmap['w']}
  print(root.find('w:body/w:sectPr/w:pgMar', ns)
  </code></pre>
  
  <p>but I can't figure out how to grab the attributes.</p>
  
  <pre><code>print(root.find('w:body/w:sectPr/w:pgMar', ns).attrib['w:footer'])
  </code></pre>
  
  <p>doesn't appear to work.</p>