Consider I have two HTML files that are structurally identical except for the language used to fill each element (i.e., English vs. Spanish).
In the first file, I’m going to add a custom element somewhere in the file. That tag can be standalone or embedded in a paragraph (<p><mytag></mytag></p>
) or a list item / table row:
<table>
<tbody>
<tr>
<mytag></mytag>
</tr>
</tbody>
</table>
Using C# (potentially HtmlAgilityPack), how can I best determine where the <mytag>
element needs to be added in the second file, and then populate it accordingly?
Here are two sample HTML files:
File 1
<p>Some paragraph 1</p>
<h3>Before you begin</h3>
<mytag id="789123"></mytag> <-------
<p>To navigate... <a href="https://www.google.com">Learn more about...</a></p>
<h2>Heading</h2>
<h3>Subheading</h3>
<p>The page lets you...</p>
<p><mytag id="123456"></mytag></p> <-------
<p>The page has...</p>
File 2
<p>Algún párrafo 1</p>
<h3>Antes de que empieces</h3>
<p>Para navegar... <a href="https://www.google.com">Aprender más acerca de...</a></p>
<h2>Título</h2>
<h3>Subtítulo</h3>
<p>La página te permite...</p>
<p>La página tiene...</p>
File 2 – Desired final state
<p>Algún párrafo 1</p>
<h3>Antes de que empieces</h3>
<mytag id="789123"></mytag> <------- Added as a standalone element
<p>Para navegar... <a href="https://www.google.com">Aprender más acerca de...</a></p>
<h2>Título</h2>
<h3>Subtítulo</h3>
<p>La página te permite...</p>
<p><mytag id="123456"></mytag></p> <------- Added with <p> wrapper
<p>La página tiene...</p>