删除EWS EmailMessage正文中的HTML部分

问题描述 投票:0回答:2

我想在通过HTML中的EWS EmailMessage回复之前删除.Body.Text ResponseMessage值的C#内容的一部分

要删除的内容如下,它们包含可单击和不可单击的html按钮。

[我看到我们无法声明自己的自定义标签,因此无法通过定位自定义html标签来使用string.replace

我能否知道我的任务是否有解决方法,例如将下面的内容放在占位符中,等等?

<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%">
<tbody>
<tr>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="30%" style="width:30.0%;background:#17202A;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white">ACTION: ADD
<o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="30%" style="width:30.0%;background:#17202A;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white">ACTION: MINUS
<o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="20%" style="width:20.0%;background:#3A69C2;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white"><a href="mailto:test.com?subject=[MULTIPLY];body=ACTION:%20MULTIPLY"><span style="color:white;background:#3A69C2;text-decoration:none">MULTIPLY
</span></a><o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="20%" style="width:20.0%;background:#3A69C2;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white"><a href="mailto:test.com?subject=[DIVIDE];body=ACTION:%20DIVIDE"><span style="color:white;background:#3A69C2;text-decoration:none">DIVIDE
</span></a><o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
c# html css exchangewebservices
2个回答
0
投票

您能否使用html标签https://www.w3schools.com/tags/att_id.asp的Id属性标识要删除的标签?


0
投票

假设您要删除包含“乘”和“除”按钮的表,并且在文档的其他任何地方都找不到它们,我们可以将它们与XPath结合使用以查找表并将其删除。您可以使用inbuild XMLDocument类,但由于它是HTML,因此我建议使用HTMLAgilityPack(作为nuget包提供)来解析HTML。

您最终会得到类似的东西:

//Create a HTMLAgilityPack Document
HtmlDocument doc = new HtmlDocument();
//Load the email body
doc.LoadHtml(EmailMessage.Body.Text);
//Select the ancestor table of the link we're interested in
HtmlNode node = doc.DocumentNode.SelectSingleNode("//a[@href='mailto:test.com?subject=[DIVIDE];body=ACTION:%20DIVIDE']//ancestor::table");
//Remove the table
node.Remove();

//Get the new email body
string newBody = doc.DocumentNode.InnerHtml;

您可能需要进行一些调整才能到达目的地,但希望这是一个好的开始。

© www.soinside.com 2019 - 2024. All rights reserved.