忽略xhtml命名空间下带有xmldiff的样式标签

问题描述

我正在使用xmldiff在两个xhtml文件显示差异。根据{{​​3}},有一种方法可以忽略结果文件中的样式标签

有人知道我怎么能将xhtml:b识别为样式标签? 这些是我的文件

<xml xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <xhtml:div>one two three four</xhtml:div>
</xml>

<xml xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <xhtml:div>
       one two 
       <xhtml:b>three</xhtml:b>
       four 
    </xhtml:div>
</xml>

我尝试从以下位置更改格式器参数:

formatter = HTMLFormatter(
    text_tags=('p','h1','h2','h3','h4','h5','h6','li','div'),formatting_tags=('b','u','i','strike','em','super','sup','sub','link','a','span')
    )

formatter_xhtml = HTMLFormatter(
    text_tags=('xhtml:p','xhtml:h1','xhtml:h2','xhtml:h3','xhtml:h4','xhtml:h5','xhtml:h6','xhtml:li','xhtml:div'),formatting_tags=('xhtml:b','xhtml:u','xhtml:i','xhtml:strike','xhtml:em','xhtml:super','xhtml:sup','xhtml:sub','xhtml:link','xhtml:a','xhtml:span')
    )

但是我只有这个错误

Traceback (most recent call last):
  File "c:/Users/paolo/Documents/12_raw_handle/test.py",line 89,in <module>
    formatter=formatter_xhtml)
  File "C:\Python27\lib\site-packages\xmldiff\main.py",line 45,in diff_texts
    diff_options=diff_options,formatter=formatter)
  File "C:\Python27\lib\site-packages\xmldiff\main.py",line 39,in _diff
    formatter=formatter)
  File "C:\Python27\lib\site-packages\xmldiff\main.py",line 21,in diff_trees
    formatter.prepare(left,right)
  File "C:\Python27\lib\site-packages\xmldiff\formatting.py",line 322,in prepare
    self.placeholderer.do_tree(left_tree)
  File "C:\Python27\lib\site-packages\xmldiff\formatting.py",line 162,in do_tree
    for elem in tree.xpath('//'+'|//'.join(self.text_tags)):
  File "src\lxml\etree.pyx",line 1582,in lxml.etree._Element.xpath
  File "src\lxml\xpath.pxi",line 305,in lxml.etree.XpathelementEvaluator.__call__
  File "src\lxml\xpath.pxi",line 225,in lxml.etree._XPathEvaluatorBase._handle_result
lxml.etree.XPathEvalError: Undefined namespace prefix

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)