1
我正在使用lxml写出一个cXML文件,但我不知道如何让它写出开头<?xml version="1.0" encoding="UTF-8"?>
以及其后的文档类型。当我开始这个时,我直接开始阅读文档本身,第一个元素是cXML timestamp="2015-02-01'T'12:00:00Z">'
等等。现在我意识到我可能因为没有开始标记和doctype定义而出现解析错误,但我不知道如何让lxml如何写出这些错误。如何在lxml中编写一个xml文档的开头?
完美地工作。为了将其写入文件,我使用了:'treeStr = ET.tostring(topline,encoding =“UTF-8”,xml_declaration = True,doctype ='''<!DOCTYPE cXML SYSTEM“http://xml.cXML (str(orderNumber)+“.xml”,'w') xmlFile.write(treeStr)'.org/schemas/cXML/1.2.011/InvoiceDetail.dtd“>''') xmlFile = – Bendustries 2015-02-15 05:49:27