ElementTree (Python 2.7) does not see the attributes of the root element, for example, for tag <w:document xmlns:w="http://ift.tt/JiuBoE"> - get an empty dictionary. I want "on the fly"to get the namespace for working with tags. Library xml.dom.minidom works fine, but I don't want to lose features with ET. Code example:
from xml.etree import ElementTree as ET
import zipfile
path = '/path/to/sample.docx'
zf = zipfile.ZipFile(path, 'r')
root = ET.fromstring(zf.read('word/document.xml'))
print(root.tag, root.attrib) # =>
# ('{http://ift.tt/1meWNuL', {})
No comments:
Post a Comment