0

How can I write xml file into the invoices in the code? I've tried in many ways but I get minidg to get out.xml empty.

Thank you.

import xml.etree.ElementTree as ET 
import sys

doc = ET.parse('01-K011116_K011169.xml')
for invoice in doc.findall('bizonylat'):
    invoices = ET.dump(invoice)
    print(invoices) 
invoices.write('out.xml')

XML structure:

<konyveles>
<program>Kontír FB </program>
<verzio>1.12.2.8</verzio>
<feladdatum>2014.01.26</feladdatum>
<feladido>17:05:38</feladido>
<cegnev>Cég neve</cegnev>
<felhasznalo>Tulajdonos</felhasznalo>
<bizonylat>
<bizonylatszam>V3</bizonylatszam>
<biz_egyedi_id/><konyv_dat>2013.01.24</konyv_dat><teljesites_dat>2013.02.11</teljesites_dat><esedekesseg_dat>2013.03.20</esedekesseg_dat>
<partneradat></partneradat>
<bizonylat_netto>628937,00</bizonylat_netto><bizonylat_brutto>798750,00</bizonylat_brutto>
<kontirozasok>
</kontirozasok>
</bizonylat>

V3 2013.01.242013.02.112013.03.20 628937,00798750,00

3r1c
  • 3
  • 2
  • 1
    Can you please be more precise? What is wrong with your code? Any error? Files are not written? What is excatly expected result? – running.t Jul 19 '18 at 10:28
  • "write xml file into the invoices". What does that mean? We cannot run the code in the question since you have not shown us the contents of 01-K011116_K011169.xml. Also note that `dump` should be used for debugging only (https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.dump). – mzjn Jul 19 '18 at 10:34
  • The program will search for all "voucher" items in the xml file. It puts the searched values into the invoices variable. If I print invoices you can see all of them, but if I want to write it in out.xml then I get a blank result. – 3r1c Jul 19 '18 at 10:37
  • Should there be a separate output file for each "voucher/bizonylat"? – mzjn Jul 19 '18 at 14:25
  • Only one output file is out.xml. Is this a problem? – 3r1c Jul 19 '18 at 16:47

0 Answers0