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

  • SEARCH
  • Home
  • 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 (400MB) initial_data.json file. Django's eating up all my memory trying
This is one of the entries I have in a huge XML file of
I have to read a huge xml file which consists of over 3 million
I have been using DOM for a long time and as such DOM parsing
We have a huge code base, where methods with too many local variables alone
I have existing application which uses Sql server 2005 as a backend. It contains
I'm supposed to do the fallowing: 1) read a huge (700MB ~ 10 million
I'm trying to find a way to open resources whose name is determined at
I've been following Hadoop for a while, it seems like a great technology. The
I am designing a web interface to a certain hardware appliance that provides its

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.