python增加xml序列小工具-界面版

 1.python处理xml代码如下

import datetime
import xml.dom.minidom
import random
import re
import sys
import tkinter as tk



#设置主窗口
window=tk.Tk()
#设置主窗口标题栏
window.title('自动添加报文序列')
window.geometry('800x500')

l01=tk.Label(window,text='清输入原报文:')
l01.place(x=30,y=10,anchor='nw')
t01=tk.Text(window,height=12)
t01.place(x=30,y=30,anchor='nw')


def increase_copy_res():
	content=t01.get('1.0','end-1c')#获取第二个窗格的内容
	newcontent=[line for line in content.splitlines() if line.strip()] #去掉空行
	datasource='\n'.join(newcontent)
	

	tree=xml.dom.minidom.parseString(datasource) #minidom模块只支持utf-8格式文档

	num=str(random.randint(10000000,99999999))

	#获取某个标签
	ele01=tree.getElementsByTagName('id')[0]
	newid='202402213000'+num
	ele01.firstChild.data=newid

	root=tree.documentElement
	t02.delete('1.0','end-1c')#清除窗格内容后再赋值
	t02.insert('insert','<?xml version="1.0" encoding="GBK"?>\n')
	t02.insert('insert',root.toxml())#给第二个窗格赋值

	content01=t02.get('1.0','end-1c')#获取第二个窗格的内容
	window.clipboard_clear()#清除剪贴板内容
	window.clipboard_append(content01)#给剪贴板赋值
	window.update()#更新剪贴板


b=tk.Button(window,text='增加序列并复制到剪贴板',width=20,height=3,command=increase_copy_res)
b.place(x=620,y=180,anchor='nw')

l02=tk.Label(window,text='结果预览:')
l02.place(x=30,y=210,anchor='nw')

t02=tk.Text(window,height=16)
t02.place(x=30,y=230,anchor='nw')


window.mainloop()



2.安装pyinstaller

3.打包成带一个参数的exe,打包好的文件在dist文件夹下

4.执行exe

直接双节dealwithxml.exe即可打开窗口

输入原始xml,点击按钮生成新的xml并自动复制到剪贴板

注意:要处理的xml文件不能带注释。

xml范例如下:

<?xml version="1.0" encoding="GBK"?>
<bookstore>
  <book category="cooking">
	<id>2024021312345678</id>
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="children">
	<id>2024021312345679</id>
    <title lang="en">Harry Potter</title>
    <author>J.K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="web">
	<id>2024021312345676</id>
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值