0
我已经搜索了很多关于此的帮助,但大多数有关XML和Python的信息都是关于如何读取和解析文件,而不是如何编写它们。我目前有一个脚本,它将文件夹的文件系统作为XML文件输出,但我希望这个文件包含可以在网上阅读的HTML标签。如何在系统文件夹中显示XML文件
此外,我正在寻找XML信息的图形文件夹样式显示。我已经看到这在javascript中解决,但我没有任何JavaScript的经验,所以这可能在Python中?
import os
import sys
from xml.sax.saxutils import quoteattr as xml_quoteattr
dirname = sys.argv[1]
a = open("output2.xml", "w")
def DirAsLessXML(path):
result = '<dir name = %s>\n' % xml_quoteattr(os.path.basename(path))
for item in os.listdir(path):
itempath = os.path.join(path, item)
if os.path.isdir(itempath):
result += '\n'.join(' ' + line for line in
DirAsLessXML(os.path.join(path, item)).split('\n'))
elif os.path.isfile(itempath):
result += ' <file name=%s />\n' % xml_quoteattr(item)
result += '</dir>'
return result
if __name__ == '__main__':
a.write('<structure>\n' + DirAsLessXML(dirname))
如果需要在Web浏览器中工作,则必须使用JavaScript。 – kindall 2010-12-16 22:29:21