Ruby-How to simply join/merge multiple xml files into one xml file?

ttliorangecolor

New Member
I have some data which are lying into multiple xml files. I need to do some operations on the whole data that is why I need to merge all the xml files into one before doing my desired operation on data.Pseducode of what I want to do is:\[code\]xml1 = open(1.xml)xml2 = open(2.xml)xml3 = open(3.xml)total_data_xml = merge(xml1,xml2,xml3)do_my_operation(total_data_xml)\[/code\]I want to use nokogiri but don't want to create any extra root node like this example. I also don't want to use XSL like this example. Is there any simple way of just merging multiple xml files using simple ruby/nokogiri or something else that serve my purpose?Edit:Here is my code:\[code\]xml_1 = Nokogiri::XML(File.open("sample_2_1.xml"))xml_2 = Nokogiri::XML(File.open("sample_2_2.xml"))builder = Nokogiri::XML::Builder.new do |xml_out| xml_out.Combined { xml_out.xml_1 { node = xml_1.at_xpath("//CompactData") # puts node.inspect xml_out << node.to_xml.to_str } xml_out.xml_2 { node = xml_2.at_xpath("//CompactData") xml_out << node.to_xml.to_str } } # puts xml_out end\[/code\]But, I am not getting anything in node. \[code\]CompactData\[/code\] is the root node in each xml file.
 
Back
Top