在尝试解析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站点、书籍等上找不到任何与此相关的参考资料。
这是如何工作的,更重要的是,您如何发现这一点?有没有GPath 'Rosetta Stone‘的XPath?
发布于 2010-01-22 22:22:05
像往常一样,查找信息的最佳位置是Groovy源代码本身。
解析的结果是一个groovy.util.slurpersupport.GPathResult对象。
如果查看源代码(纯java文件),您将看到getProperty(string)方法具有以下特殊运算符:
这就是所有,目前没有其他神奇的关键字。
发布于 2010-01-23 02:40:26
所有这些字符串都被视为属性。它们都不是真正的运算符。
这些呼叫通过GPathResult#getProperty路由,它专门检查gizmo的答案中列出的操作员。
https://stackoverflow.com/questions/2117739
复制相似问题