Thursday, September 17, 2009

Strange XMLParser behaviour - Groovy 1.6.4

ell right now I'm stumbling over a small thing in groovy and don't understand why this is happening.

So this is my code:


new StreamingMarkupBuilder().bind({

sop(desc: "generated for quantification") {
transform(sizedown: 0, attributes: "height", combine: true) {
header{
param(value:"retention_index")
param(value:"quantmass")
param(value:"id")
param(value:"spectra")
}
}
}


simple enough.

And that's the code to test it


def parser = new XmlParser().parse(source.getStream())

assertTrue parser.@desc != null

assertTrue parser.transform != null

assertTrue Integer.parseInt(parser.transform.@sizedown[0]) == 0
assertTrue parser.transform.@attributes[0] == "height"
assertTrue parser.transform.@combine[0] == "true"

assertTrue parser.transform.header.param[0].@value == "retention_index"
assertTrue parser.transform.header.param[1].@value == "quantmass"
assertTrue parser.transform.header.param[2].@value == "id"
assertTrue parser.transform.header.param[3].@value == "spectra"

assertTrue parser.transform.header.param.size() == 4


also pretty straight forward.

Now why is this part different...


transform(sizedown: 0, attributes: "height", combine: true)

assertTrue Integer.parseInt(parser.transform.@sizedown[0]) == 0
assertTrue parser.transform.@attributes[0] == "height"
assertTrue parser.transform.@combine[0] == "true"


and my attributes are returned as an array list compared to


header{
param(value:"retention_index")
param(value:"quantmass")
param(value:"id")
param(value:"spectra")
}

assertTrue parser.transform.header.param[0].@value == "retention_index"
assertTrue parser.transform.header.param[1].@value == "quantmass"
assertTrue parser.transform.header.param[2].@value == "id"
assertTrue parser.transform.header.param[3].@value == "spectra"


where the attributes are returned as simple string. I has to be something obvious, but right now I'm not getting it.

No comments:

Post a Comment