在尝试解析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
Run Code Online (Sandbox Code Playgroud)
(来自http://old.nabble.com/Q:-Avoiding-XPath---using-GPath-td19087210.html)
它似乎是对'spread-dot'操作符的有趣用法.我在Groovy网站,书籍等上找不到任何参考.
这是如何工作的,更重要的是,你是如何发现这一点的?那里有GPath'Rosetta Stone'的XPath吗?
giz*_*zmo 20
好吧,像往常一样,查找信息的最佳位置是Groovy源代码本身.
解析的结果是groovy.util.slurpersupport.GPathResult对象.
如果查看源代码(普通java文件),您会看到getProperty(string)方法具有以下特殊运算符:
这就是目前没有其他神奇的关键词.
归档时间: |
|
查看次数: |
9160 次 |
最近记录: |