Question: I have recursive function for make map from xml

```
def get_map(groovy.xml.slurpersupport.Node Node) {
    nodeRootName = Node.name() 
    if (Node.childNodes().size() == 0) {
        return [(nodeRootName): (Node.text())]
    } else {
        subMap = [(nodeRootName):[]]
        for (subNode in Node.childNodes()) {
            subMap.nodeRootName.add(get_map(subNode))    
        }
        return subMap
    }
}

```

But I can't call function as `.add` argument. 
I have error: `java.lang.NullPointerException: Cannot invoke method add() on null object`
How I can call `map.key` through a variable as key?

Answer: 
Try this:  

```
subMap[nodeRootName].add(get_map(subNode))

```
I do not know what version of Groovy you use. I can not find groovy.xml.slurpersupport.Node class in version 2.5.9. But consider moving creation map out of the **for** loop.

```
def get_map(groovy.xml.slurpersupport.Node Node) {
    nodeRootName = Node.name()
    if (Node.childNodes().size() == 0) {
        return [(nodeRootName): (Node.text())]
    } else {
        list = []
        for (subNode in Node.childNodes()) {
            list.add(get_map(subNode))
        }
        return [(nodeRootName):list]
    }
}

```