Q:

lxml replace node contents which are repeating

xml = '''
<?xml version='1.0' encoding='UTF-8'?>
<dataDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://www.fpml.org/FpML-5/confirmation"
  fpmlVersion="5-6">
  <trade>
    <tradeheader>
      <partyTradeIdentifier>
        <partyReference href="party1"/>
        <tradeId tradeIdScheme="http://www.partyA.com/swaps/trade-id">TW9235</tradeId>
      </partyTradeIdentifier>
    </tradeheader>
    <swap/>
  </trade>
  <party id="party1">
    <partyID>PARTYAUS33</partyID>
    <partyName>Party A</partyName>
  </party>
  <party id="party2">
    <partyID>BARCGB2L</partyID>
    <partyName>Party B</partyName>
  </party>
</dataDocument>
'''

from lxml import objectify
from lxml import etree
root = objectify.fromstring(xml)
newparties = ['Party C','Party D']
for e in root.party:
    print (root.partyName)

I want to replace PartyNames Party A and Party B 
with Party C and Party D respectively.

A:

newparties = ['Party C','Party D']
for e,n in zip(root.party, newparties):
    e.partyName._setText(n)
print etree.tostring(root, pretty_print=True)

output:
$ python x.py 
<dataDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.fpml.org/FpML-5/confirmation" fpmlVersion="5-6">
  <trade>
    <tradeheader>
      <partyTradeIdentifier>
        <partyReference href="party1"/>
        <tradeId tradeIdScheme="http://www.partyA.com/swaps/trade-id">TW9235</tradeId>
      </partyTradeIdentifier>
    </tradeheader>
    <swap/>
  </trade>
  <party id="party1">
    <partyID>PARTYAUS33</partyID>
    <partyName>Party C</partyName>
  </party>
  <party id="party2">
    <partyID>BARCGB2L</partyID>
    <partyName>Party D</partyName>
  </party>
</dataDocument>

