I need to locate the (in originalFile.html (//*[@id='divLinkHeader']/ul)) and replace with the new (of otherFile.html) for the new file (originalFile_WithNewUL.html) is saved with the new structure.
<!-- originalFile.html-->
<div class="col-md-4 col-sm-6">
<div id="headerLog" class="call-5">
<a href="#">
<img class="wa333372" src="#">
</a>
</div>
<div id="what5" class="pl-5 subtitle">
</div>
<div id="divLinkHeader" class="sub">
<ul class="list-inline list-unstyled"> <!-- <========= DELETE <ul> ?? -->
<li><a href="#">Line 1</a></li>
<li><a href="#">Line 2</a></li>
<li><a href="#">Line 3</a></li>
<li><a href="#">Line 4</a></li>
</ul>
</div>
</div>
And this is other file
<!-- otherFile.html-->
<ul class="list-inline list-unstyled">
<li><a href="#">New Line 1</a></li>
<li><a href="#">New Line 2</a></li>
<li><a href="#">New Line 3</a></li>
</ul>
I just want to replace a node on the other to save a file called "originalFile_WithNewUL.html"
And this is my code:
// ---
// Create New originalFile_WithNewUL.html
// ---
$newFile = "originalFile_WithNewUL".".html";
$html = file_get_contents("originalFile".".html");
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
////
////// create the new node from otherFile.html ???
//// $newNode = $dom->createElement('otherFile.html'); ?????
////
////// fetch and replace the old element ?????
//// $oldNode = $xpath->evaluate("//*[@id='divLinkHeader']/ul");
////
//// $results = $xpath->evaluate("//*");
////
$htmlVar = "<!-- WithNewUL -->\n";
$htmlVar = $htmlVar . $dom->saveHTML($results->item(0)) . "\n";
$htmlVar = $htmlVar . "<!-- END WithNewUL -->";
$fid=fopen($newFile,"w+");
fwrite($fid, $htmlVar);
fclose($fid);
I need to create this structure
<div class="col-md-4 col-sm-6">
<div id="headerLog" class="call-5">
<a href="#">
<img class="wa333372" src="#">
</a>
</div>
<div id="what5" class="pl-5 subtitle">
</div>
<div id="divLinkHeader" class="sub">
<ul class="list-inline list-unstyled">
<li><a href="#">New Line 1</a></li>
<li><a href="#">New Line 2</a></li>
<li><a href="#">New Line 3</a></li>
</ul>
</div>
</div>