如何创建“虚拟根”?使用Python的ElementTree? [英] How to create "virtual root" with Python's ElementTree?

查看:67
本文介绍了如何创建“虚拟根”?使用Python的ElementTree?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python的ElementTree生成XHTML文件。



但是,ElementTree.Element()只允许我创建一个标签(例如HTML) )。
我需要创建某种类型的虚拟根目录或任何其他名称,以便可以放置各种虚拟根目录,DOCTYPES等。



我该怎么办那?
谢谢

解决方案

我不知道是否有更好的方法,但是我已经看到了: p>

将基本文档创建为字符串:

 <!DOCTYPE html PUBLIC-// W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> 
< html>< / html>

然后解析该字符串以开始新文档。


I am trying to use Python's ElementTree to generate an XHTML file.

However, the ElementTree.Element() just lets me create a single tag (e.g., HTML). I need to create some sort of a virtual root or whatever it is called so that I can put the various , DOCTYPES, etc.

How do I do that? Thanks

解决方案

I don't know if there's a better way but I've seen this done:

Create the base document as a string:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html></html>

Then parse that string to start your new document.

这篇关于如何创建“虚拟根”?使用Python的ElementTree?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆