标签: nodechildren

Groovy XmlSlurper 从 NodeChildren 中获取价值

我正在解析 HTML 并尝试从一个特定节点中获取完整/未解析的值。

HTML 示例:

<html>
    <body>
        <div>Hello <br> World <br> !</div>
        <div><object width="420" height="315"></object></div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

代码:

def tagsoupParser = new org.ccil.cowan.tagsoup.Parser()
def slurper = new XmlSlurper(tagsoupParser)
def htmlParsed = slurper.parseText(stringToParse)

println htmlParsed.body.div[0]
Run Code Online (Sandbox Code Playgroud)

但是,它仅在第一个节点的情况下返回文本,而第二个节点则为空字符串。问题:如何检索第一个节点的值,以便获得:

Hello <br> World <br> !
Run Code Online (Sandbox Code Playgroud)

groovy xmlslurper html-parsing nodechildren

2
推荐指数
1
解决办法
1980
查看次数

标签 统计

groovy ×1

html-parsing ×1

nodechildren ×1

xmlslurper ×1