2011-07-08 26 views
1

我有一个包含一些HTML片段如以下示例的输入String如何使用groovy将某些HTML片段转换为XHTML?

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. 

显然,实际之一是通过复杂得多(包括链接,iamges,div的,等等),并且我想写具有以下原型的方法

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

退房这样的回答:http://stackoverflow.com/questions/3024488/xmlslurper-nekohtml-document-fragment-parsing-no-html-or-body-tags-wanted – sbglasius

回答

0

没有输入格式的描述,它可能会是一些类似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。