GroovyScript: Getting node name, sub node names and its values in array from XML
Could you help me please ?
I have an XML file like this :
Is there a way to get node name, subnode names and his associated value in an array ?
Output example :
array1 return : [node1, subnode1, node2, node3]
and array2 return : [value1, subnode_value1, value2, value3]
If I get this kind of output, I could work with indexes and compare easily some datas.
Many thanks for your future help.
Solved! Go to Solution.
why do you want node names in an array?
May be you can post both xml samples so that it would little more helpful to suggest better.
Thanks for your answer.
Indeed, I don't need the node names, it was just a "plus" for me.
I'll try to be more explicit.
If a have two xml :
Then File2 :
I want to be able to get all values from each xml in two arrays.. Even subnodes.
After parsing them, for the first XML, I want an output like : "[value1, subnode_value1, value2, value3]"
And for the second XML : "[valueA, valueB, valueC, subnode_valueC]".
I do not care about value order in arrays.
Do you think is it possible to realize it ? I don't know if it is better to use xmlslurper or another parser?
To conclude, if I have two arrays which contain XML node values, I could be able to compare them with assert :
(array[a_Value_in_XML_1] == array[other_Value_in_XML_2]
I'll use index for comparison in hard coded .. I just want each value in an array
Please find the solution on this topic :