<commit_before>require "ultracart_xml_parser/version"

require "ultracart_xml_parser/field_mapper"

require "ultracart_xml_parser/order"
require "ultracart_xml_parser/item"
require "ultracart_xml_parser/address"
require "ultracart_xml_parser/coupon"
require "ultracart_xml_parser/extended_detail"
require "ultracart_xml_parser/transaction_detail"

module UltraCartXMLParser
  def self.parse(io)
    document = Nokogiri::XML(io) do |config|
      config.options = Nokogiri::XML::ParseOptions::STRICT | Nokogiri::XML::ParseOptions::NONET
    end
    document.xpath('/export/order').map do |order|
      Order.new(order)
    end
  end
end<commit_msg>Switch to Nokogiri::XML::Reader to enable parsing large XML files<commit_after>require "ultracart_xml_parser/version"

require "ultracart_xml_parser/field_mapper"

require "ultracart_xml_parser/order"
require "ultracart_xml_parser/item"
require "ultracart_xml_parser/address"
require "ultracart_xml_parser/coupon"
require "ultracart_xml_parser/extended_detail"
require "ultracart_xml_parser/transaction_detail"

module UltraCartXMLParser
  def self.parse(io)
    document = Nokogiri::XML::Reader(io) do |config|
      config.options = Nokogiri::XML::ParseOptions::STRICT | Nokogiri::XML::ParseOptions::NONET
    end
    orders = []
    document.each do |node|
      if node.name == 'order' && node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
        orders << Order.new(Nokogiri::XML(node.outer_xml).at('./order'))
      end
    end
    orders
  end
end
{'fraction_non_alphanumeric': 0.10764119601328903, 'fraction_numerical': 0.0, 'mean_word_length': 5.753363228699552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 17}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2104852', 'n_tokens_mistral': 530, 'n_tokens_neox': 510, 'n_words': 86}