# -*- coding: utf-8 -*-
"""
@Author : Pink
@Time : 12/28/2021 3:19 PM
@Function: create_xml()生成xml报文
"""
from xml.dom import minidom
from datetime import datetime, timezone, timedelta
# 写入xml文档的方法
def create_xml():
"""
:return: xml报文
"""
tz = timezone(timedelta(hours=+8))
now = datetime.now(tz)
xml = minidom.Document()
root = xml.createElement('root')
xml.appendChild(root)
header = xml.createElement('header')
header.setAttribute('eventId', '0')
# header.setAttribute('timeStamp', now.isoformat()) # 时间戳问题
root.appendChild(header)
location = xml.createElement('location')
location.setAttribute('processName', '')
location.setAttribute('processNo', '0')
header.appendChild(location)
return xml.toprettyxml(encoding='utf-8') # 变成bytes
def save_xml(uid, xml):
f = open('xml//RequestError_' + str(uid) + ".xml", 'w') # 生成文件
f.write(xml) # 添加编码
f.close()
07-18
3318
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-22
4276
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-13
3586
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交