我正在尝试在python脚本中使用BeautifulSoup,它可以帮助我避免在IBMIDA(InfoSphereDataArchitect)ldm(逻辑数据模型)文件中进行大规模更新的手动工作,这些文件实际上是xml。除了一些副作用外,它对我很有效。xml中的description属性可以包含一些格式,其中控制字符编码为转义序列,如
、

、	
。在我的脚本输出时,它们被转换为十六进制0D
{
from bs4 import BeautifulSoup
#import os
source_modlel_file_name="TestModel.ldm"
target_model_file_name="TestModel_out.ldm"
with open(source_modlel_file_name,'r',encoding="utf-8",newline="\r\n") as source_model_file:
source_model = source_model_file.read()
soup_model=BeautifulSoup(source_model, "xml")
with open(target_model_file_name, "w",encoding="utf-8",newline="\r\n") as file:
file.write(str(soup_model))
一种解决方案是使用自定义格式化程序:
印刷品:
相关问题 更多 >
编程相关推荐