Skip to content

Instantly share code, notes, and snippets.

@igorzakhar
Created January 30, 2019 17:09
Show Gist options
  • Save igorzakhar/86fd4888682d888ecb8ef8f0e7dd9b9d to your computer and use it in GitHub Desktop.
Save igorzakhar/86fd4888682d888ecb8ef8f0e7dd9b9d to your computer and use it in GitHub Desktop.
import copy
import xml.etree.ElementTree as etree
a = ['труба', 'светильник', 'кран шаровый']
b = [3, 2, 2]
tree = etree.parse('dop_raboty_kopia.xml')
root = tree.getroot()
chapter = root.find('.//Chapters/Chapter')
position = chapter.getchildren()[1]
for i in range(len(a)):
new_position = copy.deepcopy(position)
quantity = new_position.find('Quantity')
quantity.attrib['Fx'] = str(b[i])
new_position.attrib['Caption'] = a[i]
chapter.insert(len(chapter.getchildren()), new_position)
tree.write('output.xml', encoding="windows-1251")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment