我的S005_179-205M-2格式XML file:
<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:base="http://example.org" xml:id="example_v1" >
<teiHeader>
<fileDesc>
<titleStmt>
<title>test</title>
</titleStmt>
<publicationStmt>
<p>test</p>
</publicationStmt>
<sourceDesc>
<p>test</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text xml:lang="ar">
<body>
<div type="chapter" n="5" xml:lang="ar">
<div type="section" n="5.179">
<head type="30">الْقَوْلُ فِي تَأْوِيلِ قَوْلِهِ : <quote type="quran" n="5:74">أَفَلا يَتُوبُونَ إِلَى اللَّهِ وَيَسْتَغْفِرُونَهُ وَاللَّهُ غَفُورٌ رَحِيمٌ </quote></head>
<p n="nothadith" ana="adyan kalam yes">يقول تعالى ذكره : أفلا يرجع هذان الفريقان <name
role="organization">الكافران</name> ، القائل أحدهما : <quote
type="quran" n="5:72">إِنَّ اللَّهَ هُوَ <name role="person">الْمَسِيحُ
ابْنُ مَرْيَمَ</name>
</quote> ، والآخر القائل : <quote type="quran" n="5:73">إِنَّ اللَّهَ
ثَالِثُ ثَلاثَةٍ </quote> ، عما قالا من ذلك ، و ينيبان مما قالا ونطقا به
من كفرهما ، ويسألان ربهما المغفرة مما قالا : <quote type="quran" n="5:74"
>وَاللَّهُ غَفُورٌ </quote> ، لذنوب التائبين من خلقه ، المنيبين إلى <pb
type="turki" n="8:582"/> طاعته بعد معصيتهم ، <quote type="quran"
n="5:34">رَحِيمٌ </quote> بهم في قبوله توبتَهم ، ومراجعتَهم إلى ما يحب
مما يكره ، فيصفح بذلك من فعلهم عما سلف من إجرامهم قبل ذلك . </p>
</div>
</div>
</body>
</text>
</TEI>
通过以下命令读取文件:
from lxml import etree
tree = etree.parse('S005_179-205M-2 formated.xml')
打印树
root = tree.getroot()
print(etree.tostring(root))
输出文件看起来像
它应该用阿拉伯语打印。我已经检查过解析器没有读阿拉伯语。如何确保解析器使用Unicode进行解析
下面的代码解析并从xml中提取一些信息
输出
您的解析器正在使用unicode进行解析,但
tostring
没有写入unicode使用
etree.tostring(root, encoding="unicode")
或etree.tostring(root, encoding="utf-8")
相关问题 更多 >
编程相关推荐