欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

python寫(xiě)xml文件的操作實(shí)例

系統(tǒng) 1797 0

本文實(shí)例講述了python寫(xiě)xml文件的操作的方法,分享給大家供大家參考。具體方法如下:

要生成的xml文件格式如下:

                        
              
                
                  
                     
        ma 
      
                  
                  
                     
        xiaoju 
      
                  
                
                
                   
      Springs Widgets, Inc. 
    
                
              
              
                
                   
      I think widgets are greate.You should buy lots of them forom 
      
                  
                     
        Spirngy Widgts, Inc 
      
                  
                
              
            
          

Python實(shí)現(xiàn)代碼如下:

            
from xml.dom import minidom, Node 
 
doc = minidom.Document() 
 
doc.appendChild(doc.createComment("Simple xml document__chapter 8")) 
 
#generate the book 
book = doc.createElement('book') 
doc.appendChild(book) 
 
#the title 
title = doc.createElement('title') 
title.appendChild(doc.createTextNode("sample xml thing")) 
book.appendChild(title) 
 
#the author section 
author = doc.createElement("author") 
book.appendChild(author) 
name = doc.createElement('name') 
author.appendChild(name) 
firstname = doc.createElement('first') 
firstname.appendChild(doc.createTextNode("ma")) 
name.appendChild(firstname) 
lastname = doc.createElement('last') 
name.appendChild(lastname) 
lastname.appendChild(doc.createTextNode("xiaoju")) 
 
affiliation = doc.createElement("affiliation") 
affiliation.appendChild(doc.createTextNode("Springs Widgets, Inc.")) 
author.appendChild(affiliation) 
 
#The chapter 
chapter = doc.createElement('chapter') 
chapter.setAttribute('number', '1') 
title = doc.createElement('title') 
title.appendChild(doc.createTextNode("First")) 
chapter.appendChild(title) 
book.appendChild(chapter) 
 
para = doc.createElement('para') 
para.appendChild(doc.createTextNode("I think widgets are greate.\ 
You should buy lots of them forom")) 
company = doc.createElement('company') 
company.appendChild(doc.createTextNode("Spirngy Widgts, Inc")) 
para.appendChild(company) 
chapter.appendChild(para) 
 
print doc.toprettyxml() 


          

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!?。?/p>

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 四虎在线观看一区二区 | 日日操av | 日韩一道本| avidolzvideo| 婷婷色九月综合激情丁香 | 91精品久久| 日本在线你懂的 | 天天看天天摸色天天综合网 | 三级做爰大爽视频 | 91视频免费网址 | 成人午夜在线 | 亚洲精品乱码久久久久久9色 | 91精品国模一区二区三区 | www黄色免费| 午夜视频你懂的 | 欧美成人激情在线 | 秋霞伊人| 日本黄视色视频在线观看 | 亚洲精品国产精品国自产在线 | 亚洲精品国产福利在线观看 | 国产精品亚洲一区二区三区在线 | 国产萝控精品福利视频免费观看 | 国产精品视频在线观看 | 一区二区三区视频 | 黄网页在线观看 | 99精品视频在线视频免费观看 | 国产亚洲精品久久久久久线投注 | 国产一区不卡 | 欧美日韩亚洲国内综合网俺 | 可以看av的网站 | 国产不卡视频在线 | 国产中文字幕在线观看 | 欧美日韩一级视频 | 久久99精品久久久久久噜噜 | 特黄特色大片免费视频观看 | www.91在线| 亚洲精品66| 国产成人精品视频 | 在线一区二区三区 | 精品国产黄a∨片高清在线 亚洲3atv精品一区二区三区 | 男女激情视频在线观看 |