Guest User

Untitled

a guest
Nov 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. require 'nokogiri'
  2.  
  3. def generate_xml(number_of_occurrences)
  4. lines = []
  5. lines << "<Root>\n"
  6. lines << ' <ModelFile Name="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ModellerType="aa" Unit="1" UnitFromCAD="1" VM="10" Vm="0">\n'
  7. number_of_occurrences.times do |i|
  8. occ = <<-XML
  9. <ProductOccurrence Id="#{i+1}" Name="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" PersistentId="1111111111" Layer="65535" Style="65535" Behaviour="1" FilePath="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" OriginalFilePath="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Children="1111111111111111111111111111111111111111111111111111111" ModellerType="22" ProductLoadStatus="4" ProductFlag="4" Unit="1" DensityVolumeUnit="1" DensityMassUnit="1" UnitFromCAD="1">
  10. <Transformation RelativeTransfo="1111111111111111111111111111111" />
  11. <A3DMiscMaterialPropertiesData m_dDensity="-1" />
  12. </ProductOccurrence>
  13. XML
  14. lines << occ
  15. end
  16. lines << " </ModelFile>\n"
  17. lines << "</Root>\n"
  18. lines.join('')
  19. end
  20.  
  21.  
  22. def parse_last_occurrence_id(xml)
  23. doc = Nokogiri::XML(xml)
  24. model_file = doc.root.children.select {|c| c.name == "ModelFile"}.first
  25. last_occurrence = model_file.children.select {|c| c.name == "ProductOccurrence"}.last
  26. last_occurrence["Id"]
  27. end
  28.  
  29. number_of_occurrences = 12000
  30. loop do
  31. xml = generate_xml(number_of_occurrences)
  32. last_id = parse_last_occurrence_id(xml)
  33.  
  34. if last_id.to_i != number_of_occurrences
  35. puts
  36. puts "expected last ProductOccurrence @Id to be #{number_of_occurrences}, was #{last_id}\n"
  37. last_lines = xml.split("\n").last(10).join("\n")
  38. puts "last tags in XML: \n\n#{last_lines}"
  39. # File.open("sample.xml", "w").write(xml)
  40. break
  41. end
  42.  
  43. number_of_occurrences += 50
  44. print "#{number_of_occurrences}, " # show progress
  45. end
Add Comment
Please, Sign In to add comment