url fetching from xml depending upon selection

shanti bhushan ershantibhushan at gmail.com
Tue May 18 04:06:08 EDT 2010


On May 18, 10:18 am, shanti bhushan <ershantibhus... at gmail.com> wrote:
> I have a sample.XML file
> the code is like this
>
> <?xml version="1.0" encoding="UTF-8"?>
> <opml version="1.0">
> <head>
>         <title>My Podcasts</title>
>         <dateCreated>Sun, 07 Mar 2010 15:53:26
>
> GMT</dateCreated>
>         <dateModified>Sun, 07 Mar 2010 15:53:26
>
> GMT</dateModified>
> </head>
> <body>
>   <TestCase name="Sprint_001">
>     <Input url="http://first.co.jp" />
>     <Input url="http://www.google.com" />
>     <Input url="http://www.epaper.times.india.com" />
>   </TestCase>
>   <TestCase name="Sprint_002">
>     <Input url="http://second.co.jp" />
>     <Input url="http://www.google.com" />
>     <Input url="http://www.epaper.times.india.com" />
>   </TestCase>
>   <TestCase name="Sprint_003">
>     <Input url="http://third.co.jp" />
>     <Input url="http://www.google.com" />
>     <Input url="http://www.epaper.times.india.com" />
>   </TestCase>
> </body>
> </opml>
>
> This my python code
> from xml.etree import ElementTree
>
> with open('our.xml', 'rt') as f:
>     tree = ElementTree.parse(f)
>
> for node, value in tree.findall('.//TestCase/Input'):
>
>         url=node.attrib.get('url')
>         print url
>
> i want to print the url depending on name="sprint_001".
> If i change my option to sprint_002 it should print url for sprint_002


i have tried some new things here

from xml.etree import ElementTree

with open('our.xml', 'rt') as f:
    tree = ElementTree.parse(f)

for node in tree.findall('.//TestCase/'):
    print node.attrib.keys()
    print node.attrib.items()
    print node.attrib.get(1)

    url=node.attrib.get('url')
    print url



but i am not getting idea ... how to achive my motive



More information about the Python-list mailing list