hello all,
I have another question about parsing an xml string. bellow is the xml string i am working with:
I was able to parse single nodes, such as first-name and last-name this way:HTML Code:alum_string= ""<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <person> <id>jIi-hRi4cI</id> <first-name>Jason</first-name> <last-name>Wucinski</last-name> <languages total="2"> <language> <language> <name>English</name> </language> <proficiency> <level>native_or_bilingual</level> </proficiency> </language> <language> <language> <name>Setswana</name> </language> <proficiency> <level>elementary</level> </proficiency> </language> </languages> </person> ""
but when i try to parse a node that repeats (such as language proficiency) the strings end up being grouped together and cant be separated. below is the code i use to do parse languages:Code:def alum = new XmlSlurper().parseText(alum_string) print " first name: ${alum.'first-name'} \n" print " last name: ${alum.'last-name'} \n" //output: // first name: Jason //last name: wucinski
the output iterates twice, which is good i guess since there are two languages in the above xml, but the two language names are grouped together. I would expect the output to be:Code:print("languages: ") alum.languages.each{languages -> print("${alum.languages.language.language.name} \n") //output: //languages: EnglishSetswana //languages: EnglishSetswana }
languages: English
languages: Setswana
what's going on? can anyone help? thanks in advance
jason


Reply With Quote