Tag:rank Traversal att work workspace port attr count ica
<?xml version= "1.0",
<data>
<country name= "Liechtenstein";
<rank>1</rank
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name= "Austria" direction= "E"/>
<neighbor name= "Switzerland" direction= "W"/>
</country>
<country name= "Singapore";
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc
<neighbor name= "Malaysia" direction= "N"/>
</country>
<country name= "Panama";
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
< Neighbor Name= "Costa Rica" direction= "W"/>
<neighbor name= "Colombia" direction= "E"/>
</country
</data>
>>> OS.GETCWD ()
' D:\\workspace\\testpython '
>>> Import Xml.etree.ElementTree as ET
>>> tree = et.parse (' Test.xml ')
>>> root = Tree.getroot ()
>>> Print Root
<element ' data ' at 0x1d2a8b0>
>>> Print Tree
<xml.etree.elementtree.elementtree Object at 0x01d2a9d0>
>>> Root.tag
' Data '
>>> Root.attrib
{}
>>> #遍历子节点
>>> for child in Root:
Print Child.tag,child.attrib
Country {' name ': ' Liechtenstein '}
Country {' name ': ' Singapore '}
Country {' name ': ' Panama '}
>>> Root[0].text
' \ n '
>>> Root[0][1].text
' 2008 '
>>> Root[1][3].text
>>> Root[1][2].text
' 59900 '
Life is short, I learn Python's python XML data parsing