写入现有的xml文件(python 3)

时间:2016-04-28 18:31:14

标签: xml python-3.x elementtree

我是python的新手。还在学习:)我学会了如何解析xml文档(提取一些数据)。现在我想更改xml文件中的数据。例如:更改电影或评级的描述。通过我正在使用的xml进行解析:

import xml.etree.ElementTree as etree

名为watched.xml的xml文件:

<collection shelf="My collection">
<movie title="Enemy Behind">
   <type>War, Thriller</type>
   <format>DVD</format>
   <year>2003</year>
   <imdb>9</imdb>
   <description>Talk about a US-Japan war</description>
</movie>
<movie title="Transformers">
   <type>Anime, Science Fiction</type>
   <format>DVD</format>
   <year>1989</year>
   <imdb>8</imdb>
   <description>A schientific fiction</description>
</movie>
<series title="game of thrones">
    <season titler="Winter Is Coming">
       <type> Adventure, Drama, Fantasy</type>
       <format>DVD</format>
       <episode>1</episode>
       <imdb>9.5</imdb>
       <description>Niceeeee!</description>
    </season>
    <season title="The Kingsroad">
       <type> Adventure, Drama, Fantasy</type>
       <format>DVD</format>
       <episode>2</episode>
       <imdb>9.0</imdb>
       <description>Niceee again</description>
    </season>
</series>>
</collection>

0 个答案:

没有答案