parsing XML in Python



I have an XML that I would like to parse then send the result into a txt file.


The XML file is build from blocks like this one :



<rpc-reply message-id="12"
xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<user-stats>
<allocated-user-count>10</allocated-user-count>
<current-user-count>3</current-user-count>
<max-active-user-count-24hrs>2</max-active-usercount-
24hrs>
<min-active-user-count-24hrs>0</min-active-usercount-
24hrs>
</user-stats>
</rpc-reply>


All the blocks will start with and and with


I would like to remove all the tags and get the results by line and copy them in a text file. For example :



allocated user count <tab> current-user-count <tab> max-user-count
100 <tab> 1<tab> 2<tab>
100 <tab> 0<tab> 2<tab> (info taken from the second RPC block)


etc


Is there any way I can do this?


No comments:

Post a Comment