Guest User

Untitled

a guest
Jan 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. def xml_tag_length(doc, tag_name)
  2. file = File.open("#{doc}", "r")
  3. count = 0
  4. file.each { |l| count += 1 if l.include?("</#{tag_name}>") }
  5. count
  6. end
  7.  
  8. def invs_xml_split(path, n)
  9. doc = File.open(path)
  10.  
  11. limit = xml_tag_length("#{path}", "INVOICE")
  12.  
  13. count = 0
  14. new_doc_name = 0
  15. arr = []
  16.  
  17. x = 0
  18. y = n
  19. doc.each do |line|
  20. if line.include?("<INVOICE DBOP=\"INS\" >")
  21. count += 1
  22. arr << line
  23. elsif line.include?("</INVOICE>") && (count == y || count == limit)
  24. arr << line
  25. File.open("#{new_doc_name}.XML", "a") do |f|
  26. arr.each { |element| f.write(element.to_s) }
  27. end
  28. arr = []
  29. lines = File.readlines("#{new_doc_name}.XML")
  30. File.open("#{new_doc_name}.XML", "a") { |f| f.write("</SALES_INVOICES>") } # if lines[-1].include?("</INVOICE>")
  31. 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\" >")
  32. new_doc_name += 1
  33. x += n
  34. y += n
  35. elsif count >= (x + 1) # || count == 0
  36. arr << line
  37. end
  38. end
  39. doc.close
  40. end
  41.  
  42. invs_xml_split("/home/yasin/İndirilenler/Satıs_Faturaları.XML", 5000)
Add Comment
Please, Sign In to add comment