why xml node attributes order changes after parsing with XmlSlurper?

194 Views Asked by At

The order of the attributes changes of using XmlSlurper.

Why it changes ?

We know that it doesn't affect the xml grammar. Even Is there any methods to keep the order as it is (or) Is there any methods to control the order ?

Input:

<root>
<Row Title="n1" Author="a" Genre="s"/>
<Row Title="n2" Author="b" Genre="d"/>
<Row Title="n3" Author="c" Genre="s"/>
<Row Title="n4" Author="d" Genre="f"/>
<Row Title="n5" Author="e" Genre="s"/>
<Row Title="n6" Author="f" Genre="a"/>
<Row Title="n7" Author="g" Genre="d"/>
<Row Title="n8" Author="h" Genre="d"/>
<Row Title="n9" Author="I" Genre="d"/>
</root>

Observed: After Parsed using the groovy code given below,

def root = new XmlSlurper().parse(inputfile)
root.children().each { child ->
        println child.attributes()
}

[Author:a, Title:n1, Genre:s]
[Author:b, Title:n2, Genre:d]
[Author:c, Title:n3, Genre:s]
[Author:d, Title:n4, Genre:f]
[Author:e, Title:n5, Genre:s]
[Author:f, Title:n6, Genre:a]
[Author:g, Title:n7, Genre:d]
[Author:h, Title:n8, Genre:d]
[Author:I, Title:n9, Genre:d]

Why it comes like this ?

0

There are 0 best solutions below