【发布时间】:2017-03-09 19:22:59
【问题描述】:
您好,我想创建一个内容中包含一些法语字母的 xml 文档。我确实(通过脚本)修改的 xml 标记在新的 xml 文件(我创建的那个)中具有正确的输出,但所有 xml 标记我没有修改都有一些意外字符。
#Open file
soup = BeautifulSoup(open('example2.xml'),'xml')
#...
# code that update (modify) some xml element value
#....
#write to a file
def create_a_file(content, filename = 'hello.xml'):
f = open(filename, "w")
f.write(str(content))
f.close()
#.. output of the file
# I modify this tag with a script and it displays well
<subTitl>Enquête sur le web, juillet 2010</subTitl>
# I didn't modify either the tag or the attribute but it doesn't display properly
<AuthEnty university="Université Montpellier. Centre géographique, statistique">
ésir, Pras
</AuthEnty>
如您所见,我没有修改名为 AuthEnty 的 XML 元素,但我有一些意想不到的字符。
问题 我怎样才能正确地写这个文件。是不是在打开文件没有正确解析的时候?
【问题讨论】:
标签: xml python-3.x beautifulsoup