Python basis (a) document processing

  1. xml
 1 from xml.dom.minidom import Document
 2 
 3 #文档根路径
 4 documentPath = 'E:\\ObjectOther\\Search\\PythonSearch\\document\\xml'
 5 
 6 #xml 创建
 7 doc = Document()
 8 
 9 rootElement = doc.createElement('root')
10 doc.appendChild(rootElement)
11 
12 
13 node1 = doc.createElement('node1')
14 node1Text = doc.createTextNode('2222')
15 
16 node1.appendChild(node1Text)
17 rootElement.appendChild(node1)
18 
19 # 保存文件
20 with open(documentPath + '\\1.xml', 'w', encoding='utf-8') as f:
21     doc.writexml(f, addindent='\t', newl='\n',encoding='utf-8')

reference:

https://blog.csdn.net/hu694028833/article/details/81089959

 

Guess you like

Origin www.cnblogs.com/loge/p/12365002.html