我想在尝试将xml转换为dict时删除一些字符:
data = xmltodict.parse(open('test.xml').read())
with open('test2.json', "wt", encoding='utf-8', errors='ignore') as f:
json.dump(data, f, indent=4, sort_keys=True)
return data
问题是我有很多json文件,一些json文件如下:
{
"pcrs:test A": {
"pcrs:nature": "03",
"pcrs:producteur": "SIEML"
}}
还有一些类似这样的json文件(没有PCR):
{
"test B": {
"nature": "03",
"producteur": "SIEML",
}}
如何强制像第一个示例那样的任何文件不使用'pcrs:'
作为第二个示例
这是一个名称空间前缀。因为没有包含示例XML,所以我自己编写了一个
xmltodict
允许您通过将名称空间url映射到其他表示来管理名称空间。最值得注意的是,None
将其完全移除。见Namespace Support在你的情况下,你可以这样做
将实际名称空间URL替换为
http://the/pcrs/url
相关问题 更多 >
编程相关推荐