我有.tei
以下格式的文件。
<biblStruct xml:id="b0">
<analytic>
<title level="a" type="main">The Semantic Web</title>
<author>
<persName xmlns="http://www.tei-c.org/ns/1.0">
<forename type="first">T</forename>
<surname>Berners-Lee</surname>
</persName>
</author>
<author>
<persName xmlns="http://www.tei-c.org/ns/1.0">
<forename type="first">J</forename>
<surname>Hendler</surname>
</persName>
</author>
<author>
<persName xmlns="http://www.tei-c.org/ns/1.0">
<forename type="first">O</forename>
<surname>Lassilia</surname>
</persName>
</author>
</analytic>
<monogr>
<title level="j">Scientific American</title>
<imprint>
<date type="published" when="2001-05" />
</imprint>
</monogr>
</biblStruct>
我想将上述文件转换为如下所示的.txt
格式:
T. Berners-Lee、J. Hendler 和 O. Lassilia。“语义网”,《科学美国人》,2001 年 5 月
我尝试使用以下代码:
tree = ET.parse(path)
root = tree.getroot()
s = ""
for childs in root:
for child in childs:
s= s+child.text
上面代码的问题是循环顺序执行,字符串不是顺序格式。
其次,可能还有更多的内循环。在没有手动检查的情况下提取内部循环中的内容也是有问题的。请在这件事上给予我帮助