title: How to combine two XML files with Nokogiri
body: <p>I am trying to combine two separate, but related, files with Nokogiri. I want to combine the "product" and "product pricing" if "ItemNumber" is the same. </p>
  
  <p>I loaded the documents, but I have no idea how to combine the two.</p>
  
  <p>Product File:</p>
  
  <pre><code>&lt;Products&gt;
    &lt;Product&gt;
      &lt;Name&gt;36-In. Homeowner Bent Single-Bit Axe Handle&lt;/Name&gt;
      &lt;ProductTypeId&gt;0&lt;/ProductTypeId&gt;
      &lt;Description&gt;This single bit curved grip axe handle is made for 3 to 5 pound axes. A good quality replacement handle made of American hickory with a natural wax finish. Hardwood handles do not conduct electricity and American Hickory is known for its strength, elasticity and ability to absorb shock. These handles provide exceptional value and economy for homeowners and other occasional use applications. Each Link handle comes with the required wedges, rivets, or epoxy needed for proper application of the tool head.&lt;/Description&gt;
      &lt;ActiveFlag&gt;Y&lt;/ActiveFlag&gt;
      &lt;ImageFile&gt;100024.jpg&lt;/ImageFile&gt;
      &lt;ItemNumber&gt;100024&lt;/ItemNumber&gt;
      &lt;ProductVariants&gt;
        &lt;ProductVariant&gt;
          &lt;Sku&gt;100024&lt;/Sku&gt;
          &lt;ColorName&gt;&lt;/ColorName&gt;
          &lt;SizeName&gt;&lt;/SizeName&gt;
          &lt;SequenceNo&gt;0&lt;/SequenceNo&gt;
          &lt;BackOrderableFlag&gt;N&lt;/BackOrderableFlag&gt;
          &lt;InventoryLevel&gt;0&lt;/InventoryLevel&gt;
          &lt;ColorCode&gt;&lt;/ColorCode&gt;
          &lt;SizeCode&gt;&lt;/SizeCode&gt;
          &lt;TaxableFlag&gt;Y&lt;/TaxableFlag&gt;
          &lt;VariantPromoGroupCode&gt;&lt;/VariantPromoGroupCode&gt;
          &lt;PricingGroupCode&gt;&lt;/PricingGroupCode&gt;
          &lt;StartDate xsi:nil="true"&gt;&lt;/StartDate&gt;
          &lt;EndDate xsi:nil="true"&gt;&lt;/EndDate&gt;
          &lt;ActiveFlag&gt;Y&lt;/ActiveFlag&gt;
        &lt;/ProductVariant&gt;
      &lt;/ProductVariants&gt;
    &lt;/Product&gt;
  &lt;/Products&gt;
  </code></pre>
  
  <p>Product Pricing Fields:</p>
  
  <pre><code>&lt;ProductPricing&gt;
    &lt;ItemNumber&gt;100024&lt;/ItemNumber&gt;
    &lt;AcquisitionCost&gt;8.52&lt;/AcquisitionCost&gt;
    &lt;MemberCost&gt;10.7&lt;/MemberCost&gt;
    &lt;Price&gt;14.99&lt;/Price&gt;
    &lt;SalePrice xsi:nil="true"&gt;&lt;/SalePrice&gt;
    &lt;SaleCode&gt;0&lt;/SaleCode&gt;
  &lt;/ProductPricing&gt;
  </code></pre>
  
  <p>I am looking to generate a file like this:</p>
  
  <pre><code>&lt;Products&gt;
    &lt;Product&gt;
      &lt;Name&gt;36-In. Homeowner Bent Single-Bit Axe Handle&lt;/Name&gt;
      &lt;ProductTypeId&gt;0&lt;/ProductTypeId&gt;
      &lt;Description&gt;This single bit curved grip axe handle is made for 3 to 5 pound axes. A good quality replacement handle made of American hickory with a natural wax finish. Hardwood handles do not conduct electricity and American Hickory is known for its strength, elasticity and ability to absorb shock. These handles provide exceptional value and economy for homeowners and other occasional use applications. Each Link handle comes with the required wedges, rivets, or epoxy needed for proper application of the tool head.&lt;/Description&gt;
      &lt;ActiveFlag&gt;Y&lt;/ActiveFlag&gt;
      &lt;ImageFile&gt;100024.jpg&lt;/ImageFile&gt;
      &lt;ItemNumber&gt;100024&lt;/ItemNumber&gt;
      &lt;ProductVariants&gt;
        &lt;ProductVariant&gt;
          &lt;Sku&gt;100024&lt;/Sku&gt;
          &lt;ColorName&gt;&lt;/ColorName&gt;
          &lt;SizeName&gt;&lt;/SizeName&gt;
          &lt;SequenceNo&gt;0&lt;/SequenceNo&gt;
          &lt;BackOrderableFlag&gt;N&lt;/BackOrderableFlag&gt;
          &lt;InventoryLevel&gt;0&lt;/InventoryLevel&gt;
          &lt;ColorCode&gt;&lt;/ColorCode&gt;
          &lt;SizeCode&gt;&lt;/SizeCode&gt;
          &lt;TaxableFlag&gt;Y&lt;/TaxableFlag&gt;
          &lt;VariantPromoGroupCode&gt;&lt;/VariantPromoGroupCode&gt;
          &lt;PricingGroupCode&gt;&lt;/PricingGroupCode&gt;
          &lt;StartDate xsi:nil="true"&gt;&lt;/StartDate&gt;
          &lt;EndDate xsi:nil="true"&gt;&lt;/EndDate&gt;
          &lt;ActiveFlag&gt;Y&lt;/ActiveFlag&gt;
        &lt;/ProductVariant&gt;
      &lt;/ProductVariants&gt;
    &lt;/Product&gt;
    &lt;ProductPricing&gt;
      &lt;ItemNumber&gt;100024&lt;/ItemNumber&gt;
      &lt;AcquisitionCost&gt;8.52&lt;/AcquisitionCost&gt;
      &lt;MemberCost&gt;10.7&lt;/MemberCost&gt;
      &lt;Price&gt;14.99&lt;/Price&gt;
      &lt;SalePrice xsi:nil="true"&gt;&lt;/SalePrice&gt;
      &lt;SaleCode&gt;0&lt;/SaleCode&gt;
    &lt;/ProductPricing&gt;
  &lt;/Products&gt;
  </code></pre>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>require 'csv'
  require 'nokogiri'
  
  xml = File.read('lateApril-product-pricing.xml')
  xml2 = File.read('lateApril-master-date')
  
  doc = Nokogiri::XML(xml)
  doc2 = Nokogiri::XML(xml2)
  
  pricing_data = []
  item_number = []
  
  doc.xpath('//ProductsPricing/ProductPricing').each do |file|
  
    itemNumber = file.xpath('./ItemNumber').first.text
    variant_Price = file.xpath('./Price').first.text
  
    pricing_data &lt;&lt; [ itemNumber, variant_Price ]
  
    item_number &lt;&lt; [ itemNumber ]
  end 
  
  puts item_number ## This prints all the item number but i have no idea how to loop through them and combine them with Product XML
  
  doc2.xpath('//Products/Product').each do |file|
    itemNumber = file.xpath('./ItemNumber').first.text #not sure how to write the conditions here since i don't have pricing fields available in this method
  end 
  </code></pre>