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 8072085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:54:18+00:00 2026-06-05T13:54:18+00:00

I am trying to create an XML using some list of XML’s. here is

  • 0

I am trying to create an XML using some list of XML’s.

here is an example list of XML’s

java.xml :

<JavaDetails>
   <SomeList> ... </SomeList>
   ....
</JavaDetails>

c.xml

<CDetails>
   <SomeList> ... </SomeList>
   ....
</CDetails>

I want to create a Programming.xml using the above XML’s

it should look like:

<programming>
 <Java>
   <JavaDetails>
    <SomeList> ... </SomeList>
    ....
   </JavaDetails>
 </Java>
 <C>
  <CDetails>
    <SomeList> ... </SomeList>
   ....
  </CDetails>
 </C>
</programming>

I am currently looking into nokogiri to do the same as Performance is a major factor, What I am not sure is how to create nodes for the output XML. any code help in Ruby using Nokogiri is much appreciated.

  • 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-06-05T13:54:19+00:00Added an answer on June 5, 2026 at 1:54 pm

    To create a new XML file with a specific root, it can be as simple as:

    doc = Nokogiri.XML("<programming/>")
    

    One way to add a child node to that document:

    java = doc.root.add_child('<Java/>').first
    

    To read in another XML file from disk and append it:

    java_details = Nokogiri.XML( IO.read )
    java << java_details.root
    

    Thus, if you have an array of filenames and you want to construct wrapping elements from each based on the name:

    require 'nokogiri'
    files = %w[ java.xml c.xml ]
    doc   = Nokogiri.XML('<programming/>')
    
    files.each do |filename|
      wrap_name = File.basename(filename,'.*').capitalize
      wrapper   = doc.root.add_child("<#{wrap_name} />").first
      wrapper   << Nokogiri.XML(IO.read(filename)).root
    end
    
    puts doc
    

    Alternatively, if you want to use the Builder interface of Nokogiri:

    builder = Nokogiri::XML::Builder.new do |xml|
      xml.programming do
        files.each do |filename|
          wrap_name = File.basename(filename,'.*').capitalize
          xml.send(wrap_name) do
            xml.parent << Nokogiri.XML(IO.read(filename)).root
          end
        end
      end
    end
    
    puts builder.to_xml
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse some XML (html) I downloaded using WebRequest.Create() and then read
I am trying to create java objects from xml file. I am using jaxb(unmarshalling)
I am trying to create a table using Xml/Xslt, where some of the cells
I am trying to create hyperlinks using XML information and XSLT templates. Here is
I have been trying to create an XML using the simplexml library (v2.6.2) http://simple.sourceforge.net/home.php
I'm trying to create an XML sitemap using CakePHP, from a table which has
I am trying to dynamically create an XML file using php like this: header
I'm trying to create an xml entry that looks like this using python and
I'm trying to access list data using SSRS 2008. I have created an XML
I'm trying to create a large XML tree in R. Here's a simplified version

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.