Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def xml_tag_length(doc, tag_name)
- file = File.open("#{doc}", "r")
- count = 0
- file.each { |l| count += 1 if l.include?("</#{tag_name}>") }
- count
- end
- def invs_xml_split(path, n)
- doc = File.open(path)
- limit = xml_tag_length("#{path}", "INVOICE")
- count = 0
- new_doc_name = 0
- arr = []
- x = 0
- y = n
- doc.each do |line|
- if line.include?("<INVOICE DBOP=\"INS\" >")
- count += 1
- arr << line
- elsif line.include?("</INVOICE>") && (count == y || count == limit)
- arr << line
- File.open("#{new_doc_name}.XML", "a") do |f|
- arr.each { |element| f.write(element.to_s) }
- end
- arr = []
- lines = File.readlines("#{new_doc_name}.XML")
- File.open("#{new_doc_name}.XML", "a") { |f| f.write("</SALES_INVOICES>") } # if lines[-1].include?("</INVOICE>")
- File.open("#{new_doc_name}.XML", "r+") { |f| f.write("<?xml version=\"1.0\" encoding=\"ISO-8859-9\"?>\n<SALES_INVOICES>\n") } # if lines[0].include?("<INVOICE DBOP=\"INS\" >")
- new_doc_name += 1
- x += n
- y += n
- elsif count >= (x + 1) # || count == 0
- arr << line
- end
- end
- doc.close
- end
- invs_xml_split("/home/yasin/İndirilenler/Satıs_Faturaları.XML", 5000)
Add Comment
Please, Sign In to add comment