【发布时间】:2020-03-24 08:53:14
【问题描述】:
我有一个带有命名空间的简单 XML。我无法访问命名空间内的文本。 XML 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by IRIS Business Services Limited -->
<link:linkbase xmlns:xsi="http://www.ffff.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.uhtj.org/2006/ref http://www.frsfs.org/2006/ref-2006-02-27.xsd http://www.ghi.org/in-ghi-rep-par ../core/in-ghi-rep-par.xsd http://www.rl.org/2003/linkbase http://www.rl.org/2003/rl-linkbase-2003-12-31.xsd" xmlns:in-ghi-rep-par="http://www.ghi.org/in-ghi-rep-par" xmlns:link="http://www.rl.org/2003/linkbase" xmlns:ref="http://www.rl.org/2006/ref" xmlns:rli="http://www.rl.org/2003/instance" xmlns:xlink="http://www.ffff.org/1999/xlink">
<link:referenceLink xlink:type="extended" xlink:role="http://www.rl.org/2003/role/link">
<link:loc xlink:type="locator" xlink:href="../core/in-ghi-rep.xsd#in-ghi-rep_ReportingPeriodTable" xlink:label="in-ghi-rep_ReportingPeriodTable"/>
<link:reference xlink:type="resource" xlink:label="res_1" xlink:role="http://www.rl.org/2003/role/disclosureRef" id="res_1">
<in-ghi-rep-par:Circular>DBS.No.FBC.BC.34/13.12.001/99-2000 dt April 6, 2000</in-ghi-rep-par:Circular>
</link:reference>
</link:referenceLink>
</link:linkbase>
我要做的就是检索"DBS.No.FBC.BC.34/13.12.001/99-2000 dt April 6, 2000",它是循环值。
我当前的代码如下所示。我已经探索了 ElementTree,但仍然无法获得解决方案。
from lxml import etree
tree = etree.parse("s2.xml")
root = tree.getroot()
root2.nsmap
for Circular in root.findall('{http://www.ghi.org/in-ghi-rep-par}'):
print (Circular.text)
我是解析 XML 的新手。请帮忙。
【问题讨论】:
标签: python-3.x lxml elementtree