Chinaunix首页 | 论坛 | 博客
  • 博客访问: 542700
  • 博文数量: 48
  • 博客积分: 1371
  • 博客等级: 中尉
  • 技术积分: 587
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-04 15:32
文章分类

全部博文(48)

文章存档

2013年(5)

2012年(35)

2011年(8)

分类: Python/Ruby

2012-07-19 15:37:47

from xml.dom.minidom import Document 
# Create the minidom document 
doc = Document() 
# Create the base element 
wml = doc.createElement("wml") 
doc.appendChild(wml) 
# Create the main element 
maincard = doc.createElement("card") 
maincard.setAttribute("id", "main") 
wml.appendChild(maincard) 
# Create a

element 

paragraph1 = doc.createElement("p") 
maincard.appendChild(paragraph1) 
# Give the

elemenet some text 

ptext = doc.createTextNode("This is a test!") 
paragraph1.appendChild(ptext) 
# Print our newly created XML print 
doc.toprettyxml(indent=" ") 

得到的xml文件:




   


      This is a test!
   



阅读(1289) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~