广度遍历这里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回答
-
同学加一下咱们的课程群,群里方面直接交流问题,这个问题初步感觉是groovy的版本不一致导致的。群号:749084280
00 -
从文无果
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
112021-05-07
相似问题