次のようなXMLドキュメントにいくつかのテスト構成があります。
<WapRules>
<WapRule>
<RuleTypeId>1</RuleTypeId>
<IsExact>false</IsExact>
<Keywords>
<Keyword>gmail</Keyword>
</Keywords>
</WapRule>
<WapRule>
<RuleTypeId>2</RuleTypeId>
<IsExact>false</IsExact>
<Keywords>
<Keyword>test</Keyword>
</Keywords>
</WapRule>
<WapRule>
<RuleTypeId>2</RuleTypeId>
<IsExact>true</IsExact>
<Keywords>
<Keyword>srs</Keyword>
<Keyword>sample</Keyword>
</Keywords>
</WapRule>
</WapRules>
これをグルーヴィーな設定として表現し、それを丸呑みしたいと思います。
「WapRules」は「WapRule」要素のリストであるため、これを次のようなConfig.groovyファイルにマップしようとしました。
wap_rules = [
{
rule_type_id = 1
is_exact = false
keywords = ["gmail"]
},
{
rule_type_id = 2
is_exact = false
keywords = ["test"]
},
{
rule_type_id = 2
is_exact = true
keywords = ["srs", "sample"]
}
]
そして今、私は設定を丸呑みして、要素にアクセスしようとします:
def cfg = new ConfigSlurper().parse(Config)
println cfg.wap_rules[0].rule_type_id
しかし、出力には次のようなものがあります。[:]
では、どうすれば内部のメンバーにアクセスできますcfg.wap_rules[0]
か?XML構造のConfig.groovyへのマッピングに何か問題がありますか?