“修复”的最佳方式格式错误的html用于xsl转换 [英] Best way to "fix" malformed html for use in an xsl transform

查看:109
本文介绍了“修复”的最佳方式格式错误的html用于xsl转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入xml文档,其中包含经过xml编码的格式错误的html。
即xml文档本身在技术上是有效的。

I have an input xml document that contains mal-formed html which has been xml encoded. i.e. the xml document itself is technically valid.

现在我将xsl转换应用于输出格式良好的xhtml5但包含格式错误的xml html。

Now I am applying an xsl transform to the xml which output well-formed xhtml5 but contains the mal-formed html.

坏html的例子:


  • html,head and body html片段中的标签。

  • 字体标签

  • 不匹配的引号

  • 未关闭的标签

  • 额外关闭标签,没有匹配的开放

  • 以错误的顺序关闭标签(例如< b>< u> text< / b> < / u>

  • html, head and body tags in html fragments.
  • font tags
  • mismatched quotes
  • unclosed tags
  • extra close tags with no matching open
  • close tags in the wrong order (e.g. <b><u>text</b></u>)

现在在我的情况下我实在不在乎html是形成错误 - 我只关心我的结束标签与我的开头标签相匹配,无论它们之间是什么。

Now in my situation I actually don't care that the html is mal-formed - I only care that my closing tags match my opening tags, regardless of what goes in between.

所以我的问题是 - 什么是最好的方法

So my question is - what is the best way to either


  1. 充分清理html,它不会影响其他标签(最好是在变换本身内)

  2. 或以某种方式标记壁橱ag,以便html5兼容的浏览器将其识别为匹配特定的开放标记,无论它们之间是否存在任何讨厌的标记。

for 2。我完全没有想法。我有一些想法1.例如调用外部工具如tidy或使用.NET sgml解析器

for 2. I have no ideas at all. I have a couple of ideas for 1. such as calling an external tool like tidy or using a .NET sgml parser

.NET xsl脚本( msxsl:script )是可以接受的,如果不受欢迎的话。

.NET xsl scripts (msxsl:script) are acceptable, if undesirable.

示例来源:

<xml>
  &lt;b&gt;&lt;u&gt;bad html&lt;/b&gt;&lt;/u&gt;
<xml>

示例输出:

<div id="MyDiv">
  <b><u>bad html</b></u>
</div> <!-- this /div absolutly must match the opening div regardless of what might be in the bad html -->

还有哪些其他方法?

C#,VS2012,仅限xslt 1.0

C#, VS2012, xslt 1.0 only

推荐答案

是否可以使用第三方库? HTML Agility Pack (可在NuGet上获得)可能是解决无效HTML的一部分,它也是(根据网站)支持XSLT。

Is using a third party library acceptable? The HTML Agility Pack (available on NuGet) might got part of the way to solving your invalid HTML and it also (according to the website) supports XSLT.

这篇关于“修复”的最佳方式格式错误的html用于xsl转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆