构建大学网上办事大厅与手册的自动化解决方案
]]>
import xml.etree.ElementTree as ET def generate_html(xml_file): tree = ET.parse(xml_file) root = tree.getroot() html_content = "
for service in root.findall('service'):
name = service.find('name').text
description = service.find('description').text
html_content += f"{name}{description}"
html_content += ""
return html_content
# 示例调用
html_output = generate_html("services.xml")
with open("online_service.html", "w") as f:
f.write(html_output)
]]>
from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvas def generate_pdf(xml_file, pdf_name): tree = ET.parse(xml_file) root = tree.getroot() c = canvas.Canvas(pdf_name, pagesize=letter) width, height = letter y = height - 50 for service in root.findall('service'): name = service.find('name').text description = service.find('description').text c.drawString(50, y, name) c.drawString(70, y - 20, description) y -= 40 c.save() # 示例调用 generate_pdf("services.xml", "student_manual.pdf") ]]>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!