我正在尝试将我的脚本(https://github.com/fletchermoore/n2c2)转换为使用默认包 xml.etree 而不是 lxml。这是我的疏忽,但现在我意识到让我的目标受众在他们的 Mac 上设置 lxml 是不可能的。
我认为大多数代码应该只通过切换导入来工作,但是当我尝试它时,我发现 xml.etree 以不同的方式处理命名空间(我不明白)。具体来说,在这里转换 setTagNames 函数的最简单方法是什么。xml
是从.fromstring()
方法创建的。
def setTagNames(self, xml):
officens = xml.nsmap['office']
textns = xml.nsmap['text']
drawns = xml.nsmap['draw']
xlinkns = xml.nsmap['xlink']
stylens = xml.nsmap['style']
fons = xml.nsmap['fo']
names = {}
names['body'] = '{%s}body' % officens
names['text'] = '{%s}text' % officens
names['auto-styles'] = '{%s}automatic-styles' % officens
names['list'] = '{%s}list' % textns
names['list-item'] = '{%s}list-item' % textns
names['p'] = '{%s}p' % textns
names['line-break'] = '{%s}line-break' % textns
names['tab'] = '{%s}tab' % textns
names['span'] = '{%s}span' % textns
names['frame'] = '{%s}frame' % drawns
names['image'] = '{%s}image' % drawns
names['href'] = '{%s}href' % xlinkns
names['name'] = '{%s}name' % stylens
names['style-name'] = '{%s}style-name' % textns
names['font-weight'] = '{%s}font-weight' % fons
names['text-underline-style'] = '{%s}text-underline-style' % stylens
names['font-style'] = '{%s}font-style' % fons
names['font-size'] = '{%s}font-size' % fons
names['background-color'] = '{%s}background-color' % fons
names['color'] = '{%s}color' % fons
names['style'] = '{%s}style' % stylens
names['text-properties'] = '{%s}text-properties' % stylens
self.names = names
self.builder.names = names