【问题标题】:How can I transform some HTML fragment into XHTML using groovy?如何使用 groovy 将一些 HTML 片段转换为 XHTML?
【发布时间】:2013-02-10 10:14:50
【问题描述】:

我有一个输入 String 包含一些 HTML 片段,如下例所示

I would have enever thought that <b>those infamous tags</b>, 
born in the <abbr title="Don't like that acronym">SGML</abbr> realm,
would make their way into the web of objects that we now experience.

显然,真实的要复杂得多(包括链接、图像、div 等),我想编写一个具有以下原型的方法

String toXHTML(String html) {
     // What do I have to write here ?
}

【问题讨论】:

标签: html xhtml groovy


【解决方案1】:

如果没有输入格式的描述,它可能会是一些类似 html 的东西。 解析这样的混乱很快就会变得丑陋。但看起来其他人已经做得很好了:

#!/usr/bin/env groovy
@Grapes(
    @Grab(group='jtidy', module='jtidy', version='4aug2000r7-dev')
)
import org.w3c.tidy.*
def tidy = new Tidy()
tidy.parse(System.in, System.out)

使用原力,Riduidel。

【讨论】:

    【解决方案2】:

    看看这个:http://blog.foosion.org/2008/06/09/parse-html-the-groovy-way/ 这可能是您正在寻找的东西。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-20
    • 2014-03-30
    • 2010-09-13
    • 1970-01-01
    • 2012-08-19
    • 2021-11-17
    相关资源
    最近更新 更多