Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:17:47+00:00 2026-06-16T05:17:47+00:00

I have some test config in an XML doc like this: <WapRules> <WapRule> <RuleTypeId>1</RuleTypeId>

  • 0

I have some test config in an XML doc like this:

<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>

I want to represent this as a groovy config and then slurp it in.

“WapRules” is a list of “WapRule” elements, so I tried to map this to a Config.groovy file like this:

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"]
    }
]

and now I slurp in the config and try to access the elements:

def cfg = new ConfigSlurper().parse(Config)
println cfg.wap_rules[0].rule_type_id

but the output just has this: [:]

So how can I access the members inside cfg.wap_rules[0] ? Is there something wrong with my mapping of XML structure to Config.groovy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:17:49+00:00Added an answer on June 16, 2026 at 5:17 am

    Got the answer. I wasn’t mapping the XML document properly.

    Here’s how I should have written my 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"]
        ]
    
    ]
    

    wap_rules is now a list of maps, and each map’s elements can be accessed easily.

    Now I can indeed do println cfg.wap_rules[0].rule_type_id and the output is indeed 1

    I guess I was too conditioned by JSON representation (i.e. “I need a list of JSON objects, each one in braces {}”) when I wrote the erroneous Config.groovy.

    I hope this helps someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some test class TestKlass = (function() { function TestKlass(value) { this.value =
I have some classes(call it Class A) which I would like to unit test
This is config.xml of some module: <config> <modules> <My_Example> <version>1.0.0.0</version> </My_Example> </modules> <frontend> <routers>
I would like to define some properties in my logback.xml config file and saw
I have some test cases. The test cases rely on data which takes time
I have some useful wpf buttons to test some functionality. It would be good
I have to test some things on a project which has been developed by
I have some unit tests I've written to test my Django application. One test
I have some code that attempts to test whether my application is running with
I have some .csv files which I'm using as part of a test bench.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.