问题描述:
写jmx文件后,文件首行无<?xml version='1.0' encoding='UTF-8'?>
原因分析:
查阅xml.etree.ElementTree API`文档
write(file, encoding="us-ascii", xml_declaration=None, default_namespace=None, method="xml", *, short_empty_elements=True)
项目中实际调用为tree.write(jmxPath,encoding='UTF-8')
,即默认xml_declaration=None
,写jmx文件时不写入xml声明
解决办法:
将tree.write(jmxPath,encoding='UTF-8')
改成
tree.write(jmxPath,encoding='UTF-8',xml_declaration=True)