XML : How to ignore specific tags in xml files?

At some point in my xml file I have contributor with

  <revision>        <id>1</id>        <timestamp>2012-10-25T15:50:18Z</timestamp>        <contributor>          <ip>127.0.0.1</ip>        </contributor>  </revision>    

At another point in my xml file have contributor with

  <revision>        <id>2</id>        <parentid>1</parentid>        <timestamp>2012-10-26T20:13:56Z</timestamp>        <contributor>          <username>Reedy</username>          <id>2</id>        </contributor>  </revision>    

I wrote a python script which will parse through the xml files and return whatever tags we need into a output file. But under my contributor I had two different things Ip and username, id. I would like to ignore Ip and only want to write username and id into my output file. If have both I am getting a key error like KeyError: 'username'

No comments:

Post a Comment