
1、概念
XML 格式的数据既便于机器读取,也便于人工读取。
xml 格式说明:
Tag: 使用<和>包围的部分;
Element:被Tag包围的部分,如 2003,可以认为是一个节点,它可以有子节点;
Attribute:在Tag中可能存在的 name/value 对,如示例中的 title="Enemy Behind",一般表示属性。
2、实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?xml version= "1.0" encoding= "UTF-8" ?>
<collection shelf= "New Arrivals" >
<movie title= "Enemy Behind" >
<type>War, Thriller</type>
<format>DVD</format>
<year>2003</year>
<rating>PG</rating>
<stars>10</stars>
<description>Talk about a US-Japan war</description>
</movie>
<movie title= "Transformers" >
<type>Anime, Science Fiction</type>
<format>DVD</format>
<year>1989</year>
<rating>R</rating>
<stars>8</stars>
<description>A schientific fiction</description>
</movie>
<movie title= "Trigun" >
<type>Anime, Action</type>
<format>DVD</format>
<episodes>4</episodes>
<rating>PG</rating>
<stars>10</stars>
<description>Vash the Stampede!</description>
</movie>
<movie title= "Ishtar" >
<type>Comedy</type>
<format>VHS</format>
<rating>PG</rating>
<stars>2</stars>
<description>Viewable boredom</description>
</movie>
</collection>
|
以上就是python XML数据的介绍,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。