<p>You can use Xpath expressions to address specific elements. On your snippet that would be <code>/ListRecords/record</code>. However I think it misses the document element node with the namespace declaration for the Open Archives Initiative Protocol for Metadata Harvesting. It should be something like:</p>
<pre><code>&lt;OAI-PMH xmlns=&quot;http://www.openarchives.org/OAI/2.0/&quot;&gt;
 &lt;ListRecords&gt;
  &lt;record&gt;
    &lt;header&gt;
      &lt;identifier&gt;oai:arXiv.org:hep-th/9901001&lt;/identifier&gt;
    &lt;/header&gt;
  &lt;/record&gt;
 &lt;/ListRecords&gt;
&lt;/OAI-PMH&gt;
</code></pre>
<p>To address the namespace with Xpath you need to register a prefix for it. Then put the feed urls in an array and iterate them:</p>
<pre><code>$mergeDocument = new DOMDocument();
$mergeDocument-&gt;loadXML(
    '&lt;OAI-PMH xmlns=&quot;http://www.openarchives.org/OAI/2.0/&quot;&gt;&lt;ListRecords/&gt;&lt;/OAI-PMH&gt;'
);
$mergeTarget = $mergeDocument-&gt;documentElement-&gt;firstChild;

foreach ($feedUrls as $feedUrl) {
    $document = new DOMDocument();
    $document-&gt;load($feedUrl);
    $xpath = new DOMXpath($document);
    $xpath-&gt;registerNamespace('oai', 'http://www.openarchives.org/OAI/2.0/');

    foreach ($xpath-&gt;evaluate('/oai:OAI-PMH/oai:ListRecords/oai:record') as $record) {
        $mergeTarget-&gt;appendChild($mergeDocument-&gt;importNode($record, TRUE));
    }
}
$mergeDocument-&gt;formatOutput = TRUE;
echo $mergeDocument-&gt;saveXML();
</code></pre>
HTML DOM Merge paged XML file into single file with a loop
<p>Hey I'm working on an import for a list of elements. The code works for now, but it is not futureproof if there are more items added. The XML uses an unique key and pagination (every 100 items a new key).</p>
<p>Below is my PHP code for the function I've build.</p>
<pre><code>&lt;?php 
  $feedUrl = '[url of the feed]';

  $doc1 = new DOMDocument();
  $doc1-&gt;load($feedUrl);
  $doc1_token = $doc1-&gt;getElementsByTagName('resumptionToken')[0]-&gt;nodeValue;

  $doc2 = new DOMDocument();
  $doc2-&gt;load($feedUrl . '&amp;resumptionToken=' . $doc1_token);
  $doc2_token = $doc2-&gt;getElementsByTagName('resumptionToken')[0]-&gt;nodeValue;

  $doc3 = new DOMDocument();
  $doc3-&gt;load($feedUrl . '&amp;resumptionToken=' . $doc2_token);
  $doc3_token = $doc3-&gt;getElementsByTagName('resumptionToken')[0]-&gt;nodeValue;

  $doc4 = new DOMDocument();
  $doc4-&gt;load($feedUrl . '&amp;resumptionToken=' . $doc3_token);
  $doc4_token = $doc4-&gt;getElementsByTagName('resumptionToken')[0]-&gt;nodeValue;

  $doc5 = new DOMDocument();
  $doc5-&gt;load($feedUrl . '&amp;resumptionToken=' . $doc4_token);
  $doc5_token = $doc5-&gt;getElementsByTagName('resumptionToken')[0]-&gt;nodeValue;

  // get 'ListRecordes' element of document 1
  $list_records = $doc1-&gt;getElementsByTagName('ListRecords')-&gt;item(0); //edited res - items

  // iterate over 'item' elements of document 2
  $items2 = $doc2-&gt;getElementsByTagName('record');

  for ($i = 0; $i &lt; $items2-&gt;length; $i ++) {
      $item2 = $items2-&gt;item($i);

      // import/copy item from document 2 to document 1
      $item1 = $doc1-&gt;importNode($item2, true);

      // append imported item to document 1 'res' element
      $list_records-&gt;appendChild($item1);

  }

  // iterate over 'item' elements of document 3
  $items3 = $doc3-&gt;getElementsByTagName('record');
  for ($i = 0; $i &lt; $items3-&gt;length; $i ++) {
      $item3 = $items3-&gt;item($i);

      // import/copy item from document 3 to document 1
      $item1 = $doc1-&gt;importNode($item3, true);

      // append imported item to document 1 'res' element
      $list_records-&gt;appendChild($item1);

  }

  // iterate over 'item' elements of document 4
  $items4 = $doc4-&gt;getElementsByTagName('record');
  for ($i = 0; $i &lt; $items4-&gt;length; $i ++) {
      $item4 = $items4-&gt;item($i);

      // import/copy item from document 4 to document 1
      $item1 = $doc1-&gt;importNode($item4, true);

      // append imported item to document 1 'res' element
      $list_records-&gt;appendChild($item1);

  }

  // iterate over 'item' elements of document 5
  $items5 = $doc5-&gt;getElementsByTagName('record');
  for ($i = 0; $i &lt; $items5-&gt;length; $i ++) {
      $item5 = $$items5-&gt;item($i);

      // import/copy item from document 5 to document 1
      $item1 = $doc1-&gt;importNode($item5, true);

      // append imported item to document 1 'res' element
      $list_records-&gt;appendChild($item1);

  }
  $doc1-&gt;save('merged.xml'); //edited -added saving into xml file
</code></pre>
<p>I think the code is not perfect, because if the we add more records than 600, the latest one's are not imported in the merged xml.</p>
<p>Besides this there is also an other issue. We have nested &quot;&quot; nodes. We need to merge the &quot;&quot; direct childs only.</p>
<pre><code>&lt;ListRecords&gt;
&lt;record&gt;
&lt;header&gt;
...
&lt;/header&gt;
&lt;metadata&gt;
&lt;record xmlns=&quot;http://www.openarchives.org/OAI/2.0/&quot; priref=&quot;100000002&quot;&gt;
...
&lt;/record&gt;
&lt;/metadata&gt;
&lt;/record&gt;
&lt;/ListRecords&gt;
</code></pre>