url fetching from xml depending upon selection

Stefan Behnel stefan_ml at behnel.de
Tue May 18 04:26:47 EDT 2010


shanti bhushan, 18.05.2010 10:08:
> On May 18, 12:04 pm, Stefan Behnel<stefan... at behnel.de>  wrote:
>> shanti bhushan, 18.05.2010 07:18:
 >>> [...]
>>> <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".
>>
>>       for test_case in tree.findall('.//TestCase'):
>>           if test_case.get('name') == 'sprint_002':
>>              for input_el in test_case:
>>                  print input_el.get('url')
>>
> i tried your logic i am not getting any out put for this

Obviously, because the correct name value is 'Sprint_002', not 
'sprint_002'. Please ask back if you need help in understanding the code I 
posted.

Stefan




More information about the Python-list mailing list