您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

用python迭代编写XML节点

用python迭代编写XML节点

Fredrik Lundh的elementtree.SimpleXMLWriter将使您逐步写出XML。这是模块中嵌入的演示代码

from elementtree.SimpleXMLWriter import XMLWriter
import sys

w = XMLWriter(sys.stdout)

html = w.start("html")

w.start("head")
w.element("title", "my document")
w.element("Meta", name="generator", value="my application 1.0")
w.end()

w.start("body")
w.element("h1", "this is a heading")
w.element("p", "this is a paragraph")

w.start("p")
w.data("this is ")
w.element("b", "bold")
w.data(" and ")
w.element("i", "italic")
w.data(".")
w.end("p")

w.close(html)
python 2022/1/1 18:38:41 有257人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶