Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 793275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:07:30+00:00 2026-05-14T22:07:30+00:00

I have a huge XML(>400MB) containing products. Using a DOM parser is therefore excluded,

  • 0

I have a huge XML(>400MB) containing products. Using a DOM parser is therefore excluded, so i tried to parse and process it using a pull parser. Below is a snippet from the each_product(&block) method where i iterate over the product list.

Basically, using a stack, i transform each <product> ... </product> node into a hash and process it.

while (reader.read)
  case reader.node_type
    #start element
    when Nokogiri::XML::Node::ELEMENT_NODE
      elem_name = reader.name.to_s
      stack.push([elem_name, {}])

    #text element
    when Nokogiri::XML::Node::TEXT_NODE, Nokogiri::XML::Node::CDATA_SECTION_NODE
      stack.last[1] = reader.value

    #end element
    when Nokogiri::XML::Node::ELEMENT_DECL
      return if stack.empty?

      elem = stack.pop
      parent = stack.last
      if parent.nil?
        yield(elem[1])
        elem = nil
        next
      end

      key = elem[0]
      parent_childs = parent[1]
    # ... 
      parent_childs[key] =  elem[1]
    end

The issue is on self-closing tags (EG <country/>), as i can not make the difference between a ‘normal’ and a ‘self-closing’ tag. They both are of type Nokogiri::XML::Node::ELEMENT_NODE and i am not able to find any other discriminator in the documentation.

Any ideas on how to solve this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:07:31+00:00Added an answer on May 14, 2026 at 10:07 pm

    There is a feature request on project page regarding this issue (with the corresponding failing test).

    Until it will be fixed and pushed into the current version, we’ll stick with good’ol

    input_text.gsub! /<([^<>]+)\/>/, '<\1></\1>'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge XML files up to 1-2gb, and obviously I can't parse
I have a simple but huge xml file like below. I want to parse
I have a huge bunch of XML files with the following structure: <Stuff1> <Content>someContent</name>
I have a huge database with 100's of tables and stored procedures. Using SQL
I have a huge file that I must parse line by line. Speed is
I have one huge XML document. I have set of XSL representing each node
I have a huge XML that i need to work on, but i only
So I have this huge XML file that I am converting to an object
As the title says it, I have a huge xml file (GBs) <root> <keep>
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.