lxml.etree:获取实体名称而不扩展它

时间:2013-07-16 19:46:53

标签: python xml lxml

我有以下XML:

<!ENTITY abbr "abbreviation">
<pos>&abbr;</pos>

我想获得pos节点的“未触及”的内部XML内容(即&abbr;

以下方法不起作用:

parser = etree.XMLParser(resolve_entities=False)
doc = etree.parse(inFile, parser)
print doc.find("pos").text # ! this prints "None"
print etree.tostring(doc.find("pos")) # ! this prints "<pos>&abbr;</pos>"

doc = etree.parse(inputFile)
print doc.find("pos").text # ! this prints "abbreviation"

任何简单的解决方案?

0 个答案:

没有答案