HTMLAgilityPack - how do I clone and replace x times?

38 views Asked by At

Trying to read the documentation does not quite get me there and hope someone can help.

Using HTML Agility Pack. I am reading an HTML file as a template. In this, there is a tbody with an ID Within this, there are "placeholders" or "markers" I want to replace with custom content from code.

This may need to be done x amount of times depending on the items in a collection.

How can I do this with HTMLAgilityPack?

Sample content:

<tbody id="transTable">
    <tr>
        <td>##TransID##</td>
        <td>##TermSeq##</td>
        <td>##TimeStamp##</td>
        <td>##Amount##</td>
    </tr>
</tbody>

Now, I want to get content for "transTable" Then within this, for each item in a collection - replace content with data. Append to the document/tbody node until complete.

So I may have 1 or 5 line items all with replaced content, therefore it becomes...

<tbody id="transTable">
        <tr>
            <td>123</td>
            <td>1</td>
            <td>2024-01-30</td>
            <td>400</td>
        </tr>
        <tr>
            <td>53</td>
            <td>2</td>
            <td>2024-01-31</td>
            <td>100</td>
        </tr>
        <tr>
            <td>12444</td>
            <td>534</td>
            <td>2024-01-31</td>
            <td>9</td>
        </tr>
</tbody>
0

There are 0 answers