Groovy的GPath表达式的完整语法是什么?
发布时间:2020-12-14 16:31:26 所属栏目:大数据 来源:网络整理
导读:在尝试解析Groovy中的RSS源时,我发现使用通配符的GPath示例: def text = """ data common-tables table name="address"/ table name="phone"/ /common-tables special-tables table name="person"/ /special-tables other-tables table name="business"/ /o
在尝试解析Groovy中的RSS源时,我发现使用通配符的GPath示例:
def text = """ <data> <common-tables> <table name="address"/> <table name="phone"/> </common-tables> <special-tables> <table name="person"/> </special-tables> <other-tables> <table name="business"/> </other-tables> </data> """ def xml = new XmlParser().parse(new ByteArrayInputStream(text.getBytes())) def tables = xml.'**'.table.findAll{ it.parent().name() == "special-tables" || it.parent().name (从http://old.nabble.com/Q:-Avoiding-XPath—using-GPath-td19087210.html) 它看起来像是一个有趣的使用“扩展点”运算符.我在Groovy网站,书籍等上找不到任何参考. 这是如何工作的,更重要的是,你如何发现这一点?有没有XPath的GPath“Rosetta Stone”在那里? 解决方法
那么像往常一样,找到信息的最佳地方就是Groovy源码.
解析的结果是groovy.util.slurpersupport.GPathResult对象. 如果您查看源代码(普通java文件),您将看到getProperty(string)方法具有以下特殊运算符: >“..”返回父级 就是这样,暂时没有其他魔术关键词. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |