我想将我的脚本(https://github.com/fletchermoore/n2c2)使用默认的包xml.etree代替LXML的。 这是我的疏忽,但现在我意识到这将是不可能得到我的目标受众建立LXML他们的Mac电脑。
我认为,大部分的代码应该只是通过切换出进口工作,但是当我试了一下,我发现,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