将XML内容注入标记

时间:2017-02-24 03:54:41

标签: python xml lxml

尝试构建xml并注入包含许多元素的字符串。但是通过以下方式获取错误并且不确定是什么问题。

from lxml import etree
from lxml.builder import E as e

list = ["one", "two", "three", "four", "five"]

fields = "".join("<field>{}</field>".format(x) for x in list)

xml = page = (
e.req(
  e.tab(
    e.fields(
      etree.fromstring(fields)
    )
  )
)
)

错误:

lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 1, column 20

python(2.7.10) lxml(3.7.3)

0 个答案:

没有答案