广度遍历这里children方法找不到呀

来源:5-3 xml文件解析讲解

LiYang9

2019-04-17

response.value.books返回的是NodeList对象,里面找不到children方法,是什么原因呢?我用的groovy2.5.6。
报错如下
Caught: groovy.lang.MissingMethodException: No signature of method: groovy.util.NodeList.children() is applicable for argument types: () values: []
Possible solutions: clone(), clone()
groovy.lang.MissingMethodException: No signature of method: groovy.util.NodeList.children() is applicable for argument types: () values: []
Possible solutions: clone(), clone()

写回答

2回答

qndroid

2019-04-19

同学加一下咱们的课程群,群里方面直接交流问题,这个问题初步感觉是groovy的版本不一致导致的。群号:749084280

0
0

从文无果

2021-05-02

可能只是工具没提示这个方法, 我的IDEA就没提示。

//TODO Groovy提供的广度遍历方法:children()/ '*' (这是children方法的简便写法)
def bookName = response.value.books.'*'.findAll { node ->
    //TODO class groovy.util.slurpersupport.Attributes
    println node.@id.getClass()
    //TODO class java.lang.String
    println node.name().getClass()
    //TODO @id必须转换成String, 再判断
    return '2'.equals(node.@id.toString()) && 'book'.equals(node.name())
}.collect { node ->
    return node.title.text()
}
println bookName


1
1
qndroid
赞,对,确实有可能不提示;自己手打出来,再编译是没有问题的。
2021-05-07
共1条回复

Gradle3.0自动化项目构建技术精讲+企业级案例实操

全面覆盖Gradle核心知识和高级用法,高级工程师必备技能!

877 学习 · 144 问题

查看课程