Python 2.7

No description

fork
loading
Files
  • main.py
main.py
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
from xml.etree import cElementTree as etree

xml = '''
<Catalog>
    <Books>
        <Book id="1" price="6.95">
            <Title>Do Androids Dream of Electric Sheep?</Title>
            <Author>Philip K. Dick</Author>
            <Country>USA</Country>
        </Book>
        <Book id="5" price="5.95">
            <Title>The Colour of Magic</Title>
            <Author>Terry Pratchett</Author>
            <Country>UK</Country>
        </Book>
        <Book id="7" price="6.95">
            <Title>The Eye of The World</Title>
            <Author>Robert Jordan</Author>
            <Country>USA</Country>
        </Book>
    </Books>
</Catalog>
'''

xml = etree.XML(xml)
for book in xml.findall('Books/Book[@price="6.95"][Country="USA"]'):
  print book.find('Title').text