$item_2_guid = $item_2->addChild('guid', 'https://content.jwplatform.com/videos/' . $segment_2_key . '.m4a');
         $item_2_thumb = $item_2->addChild('xlmns:itunes:image');
         $item_2_thumb->addAttribute('href', $segment_2_thumb);
         $item_2_date = $item_2->addChild('pubDate', $segment_2_pubdate);
         $item_2_duration = $item_2->addChild('xmlns:itunes:duration', $segment_2_duration);
     }
     /* Add Segment three xml */
     if ($segment_3_key) {
         /* Add item tag as a child to channel tag */
         $item_3 = $channel_xml->addChild('item');
         /**** Set tags as a child to item tag ****/
         $item_3_title = $item_3->addChild('title', $segment_3_title);
         $item_3_subtitle = $item_3->addChild('xmlns:itunes:subtitle');
         addCData($item_3_subtitle, $segment_3_subtitle);
         $item_3_summary = $item_3->addChild('xmlns:itunes:summary');
         addCData($item_3_summary, $segment_3_subtitle);
         $item_3_enclosure = $item_3->addChild('enclosure');
         $item_3_enclosure->addAttribute('url', 'https://content.jwplatform.com/videos/' . $segment_3_key . '.m4a');
         $item_3_enclosure->addAttribute('length', $segment_3_length);
         $item_3_enclosure->addAttribute('type', 'audio/x-m4a');
         $item_3_guid = $item_3->addChild('guid', 'https://content.jwplatform.com/videos/' . $segment_3_key . '.m4a');
         $item_3_thumb = $item_3->addChild('xlmns:itunes:image');
         $item_3_thumb->addAttribute('href', $segment_3_thumb);
         $item_3_date = $item_3->addChild('pubDate', $segment_2_pubdate);
         $item_3_duration = $item_3->addChild('xmlns:itunes:duration', $segment_3_duration);
     }
 }
 //endwhile;
 /* Restore original Post Data */
 wp_reset_postdata();
 wp_reset_query();
function compare($file1, $file2)
{
    global $not_exists;
    $output = '';
    if (!file_exists($file2)) {
        $not_exists[] = '<p style="color: #8b0000;"> ' . str_replace(START_DIR, '', $file2) . ' is does not exists. Tried to copy.</p>';
        //try to copy
        if (!is_dir(dirname($file2))) {
            mkdir(dirname($file2), 0777);
        }
        copy($file1, $file2);
        return false;
    }
    $xml1 = simplexml_load_file($file1);
    if (!$xml1) {
        exit($file1 . " is corrupted!");
    }
    $xml2 = simplexml_load_file($file2);
    if (!$xml2) {
        exit($file2 . " is corrupted!");
    }
    $keys1 = $keys2 = $values1 = $values2 = array();
    foreach ($xml1->definition as $def) {
        $keys1[] = (string) $def->key;
        $values1[(string) $def->key] = (string) $def->value;
    }
    foreach ($xml2->definition as $def) {
        $keys2[] = (string) $def->key;
        $values2[(string) $def->key] = (string) $def->value;
    }
    $diff = array_diff($keys1, $keys2);
    if ($diff) {
        $output .= "</br></br>Keys that not presents in <b>" . str_replace(START_DIR, '', $file2) . "</b> are:<br/>";
        foreach ($diff as $key) {
            $slice = $xml1->xpath("definition/key[text()='" . $key . "']/parent::*");
            $definition = $xml2->addChild('definition');
            $definition->addChild('key', (string) $key);
            $v = $definition->addChild('value');
            addCData($v, '????' . (string) $slice[0]->value);
            $output .= $key . '</br>';
        }
    }
    if ($output) {
        $dom = new DOMDocument("1.0");
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->loadXML($xml2->asXML());
        $string_xml = $dom->saveXML();
        $string_xml = str_replace('  ', "\t", $string_xml);
        file_put_contents($file2, $string_xml);
        $output .= "<br>";
    }
    //check non-translated items
    foreach ($keys1 as $key) {
        if ($values1[$key] == $values2[$key]) {
            $output .= "</br></br>Keys that seems not translated in <b>" . str_replace(START_DIR, '', $file2) . "</b> are:<br/>";
            $output .= $key . '</br>';
        }
    }
    return $output;
}