我正在将一些数据从另一个测试/错误跟踪工具导入到 tfs 中,我想转换它的描述,它是简单的 HTML,因此是一个纯字符串,其中保留了 HTML 的“布局”。
例如:
<body>
<ol>
<li>Log on with user Acme & Co.</li>
<li>Navigate to the details tab</li>
<li>Check the official name</li>
</ol>
<br>
<br>
Expected Result:<br>
official name is filled in<br>
<br>
Actual Result:<br>
The &-sign is not shown correctly<br>
See attachement.
</body>
将变成带有换行符和 HTML 实体翻译的纯文本,如下所示:
1. Log on with user Acme & Co. 2. Navigate to the details tab 3. Check the official name Expected Result: official name is filled in Actual Result: The &-sign is not shown correctly See attachment
我目前可以使用正则表达式用换行符替换一些标签并去除其余的,但替换 HTML 实体和类似 <ol>
的东西和 <ul>
好像我正在重新发明一些东西(浏览器?)。所以我想知道是否有人在我之前这样做过。我无法使用 Google 找到它。
最佳答案
而不是正则表达式,您可以尝试将其加载到 HTML agility pack 中?如果它是 xhtml,那么 xslt 转换可能是一个不错的选择。
关于c# - 将 Html 呈现或转换为 'formatted' 文本 (.NET),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/356597/