[Tutor] Generating XML using Python

Karim karim.liateni at free.fr
Tue Apr 12 02:40:39 CEST 2011


On 04/11/2011 07:50 PM, Karim wrote:
> On 04/11/2011 10:04 AM, tee chwee liong wrote:
>> hi Peter,
>>
>> thanks for your reply. seems that xml doesnt accept a space in between.
>> anyway, the output generated is:
>> *-* <file:///C:/Python25/myscript/cmm/port1.xml#> <Test>
>> *-* <file:///C:/Python25/myscript/cmm/port1.xml#> 
>> <Default_ConfigPort="*8*">
>> ** <LINK>*2*</LINK>
>> ** <Target_Speed>*3*</Target_Speed>
>> ** </Default_Config>
>> ** </Test>
>>
>> it overwrites every time the port number is incremented and only 
>> capture the last iteration number. how can i modify it to capture all 
>> the iteration? for eg:
>> Port 1
>> Link speed: 2
>> Target speed: 3
>> Port 2
>> Link speed: 2
>> Target speed: 3
>> Port 3
>> Link speed: 2
>> Target speed: 3
>> Port 4
>> Link speed: 2
>> Target speed: 3
>> Port 5
>> Link speed: 2
>> Target speed: 3
>> Port 6
>> Link speed: 2
>> Target speed: 3
>> Port 7
>> Link speed: 2
>> Target speed: 3
>> Port 8
>> Link speed: 2
>> Target speed: 3
>>
>> thanks
>> tcl
>>
>>
>
Sorry for the error, must remove ' Port' in iter() this example use std 
lib xml.etree.ElementTree doctree_instance obtain through parse()
method from ElementTree and it works with infinite tag 'default_Config' 
list:
> for config in doctree_instance.iter('Default_Config'):
>     link = config.find('LINK')
> target = config.find('Target_Speed')
>
>     print('Port ', config.attrib['Port'])
>     print('Link speed:', link.text)
>     print('Target speed:', target.text)
>
> Regards
>>
>>
>> _______________________________________________
>> Tutor maillist  -Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110412/fbc2efa3/attachment-0001.html>


More information about the Tutor mailing list