我有一个使用以下方法解析 XML 的脚本lxml.etree
:
from lxml import etree
parser = etree.XMLParser(load_dtd=True, resolve_entities=True)
tree = etree.parse('main.xml', parser=parser)
我需要load_dtd=True
并且resolve_entities=True
已经解决&emptyEntry;
了:globals.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE map SYSTEM "globals.xml" [
<!ENTITY dirData "${DATADIR}">
]>
<map
xmlns:map="http://my.dummy.org/map"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsschemaLocation="http://my.dummy.org/map main.xsd"
>
&emptyEntry; <!-- from globals.xml -->
<entry><key>KEY</key><value>VALUE</value></entry>
<entry><key>KEY</key><value>VALUE</value></entry>
</map>
和globals.xml
<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY emptyEntry "<entry></entry>">
现在我想从 non-standardlxml
转到 standard xml.etree
。但是我的文件失败了,因为load_dtd=True
andresolve_entities=True
不受xml.etree
.
有没有xml.etree
办法解决这些实体?