Test1
Test3

XmlSlurper. How to ignore case of @attribute name?

def doc = """
<html>
<body>
    <div tags="1">Test1</div>
    <div taGs="">Test3</div>
    <div TAGS="4">Test4</div>
</body>
</html>
"""

def html = new XmlSlurper().parseText(doc)

html.body.div.findAll { it.@tags.text()}.each { div ->
   println div.text()
}

This code prints only Test1! How to ignore @tags attribute case?

+3
source share
1 answer

Something like this should work:

def doc = """
<html>
<body>
    <div tags="1">Test1</div>
    <div taGs="">Test3</div>
    <div TAGS="4">Test4</div>
</body>
</html>
"""

def html = new XmlSlurper().parseText(doc)

html.body.div.findAll { it.attributes().find { it.key.equalsIgnoreCase( 'tags' ) }.value }.each { div ->
   println div.text()
}

As you can see, you need to manually search for attribute names to match, ignoring the case

+4
source

Source: https://habr.com/ru/post/1762792/


All Articles