[Tutor] Generating XML using Python

Karim karim.liateni at free.fr
Mon Apr 11 19:50:34 CEST 2011


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
>
>

for config in doctree_instance.iter('Default_ConfigPort'):
     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

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


More information about the Tutor mailing list