需要一种方法来搜索具有最大日期 + 值 ==“001”的条目如果我这样做是为了找到具有最大日期 + 值 ==“001”的条目,则它不起作用。有没有办法进行组合查询?def xmls = new XmlSlurper().parse(new File("C:/file.xml"));Object oTest = xmls.Test.Entry.find{ v -> v.Value == "001" }.max{ d -> Date.parse('MM/dd/yyyy', d.Date.toString()) 输入xml示例:<Test><Entry> <Date>01/12/2017</Date> <Value>001</Value></Entry><Entry> <Date>02/15/2017</Date> <Value>001</Value></Entry><Entry> <Date>03/15/2017</Date> <Value>002</Value></Entry></Test>我需要的输出是:Date>02/15/2017</Date><Value>001</Value>
1 回答
不负相思意
TA贡献1777条经验 获得超10个赞
def xmls = new XmlSlurper().parseText('''<Test>
<Entry>
<Date>01/12/2017</Date>
<Value>001</Value>
</Entry>
<Entry>
<Date>02/15/2017</Date>
<Value>001</Value>
</Entry>
<Entry>
<Date>03/15/2017</Date>
<Value>002</Value>
</Entry>
</Test>''');
Object oTest = xmls.Entry.findAll{ v -> v.Value == "001" }.max{ d -> Date.parse('MM/dd/yyyy', d.Date.toString()) }
println groovy.xml.XmlUtil.serialize(oTest)
结果:
<?xml version="1.0" encoding="UTF-8"?>
<Entry>
<Date>02/15/2017</Date>
<Value>001</Value>
</Entry>
添加回答
举报
0/150
提交
取消