Forum Discussion

shubhimu's avatar
6 years ago

How to find whether XML response tag has attribute in it using XMl slurper



I need to apply a check where in i need to check if particular xml node tag has attribute in it or not using XMl slurper

 Can any one help me with the method for the same ?

Using below code i can find out the attribute value but need help in finding the method if there is any to check whether attribute is present for the particular xml tag or not.

String str='''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ICOMS KEY="test:localhost-27d4e55f-13e6-4363-a3b7-310bb8eea75f" USERID="ASSS" PASSWORD="SSSSS" ENVIRONMENT="QA">
<ABC00053 SITEID="1">
def parsed = new XmlParser().parseText( str ) parsed.'**'*.attribute( 'HOUSNMBR' ).find()




2 Replies

  • Radford's avatar
    Super Contributor

    I don't have time at the moment to give you a detailed answer, but check out the XML Slurper documentation:



    In particular look at section 2.1 this details how to get attributes if you know which node to look at, and section 2.2 details how to look for attributes if you need to iterate over a number of nodes.

  • Olga_T's avatar
    SmartBear Alumni (Retired)

    Hi all,


    Radford, thanks for your reply.

    shubhimu, has the information that Radford provided you with helped? Or, do you need some additional details? 
    Please let us know whether any further assistance is required. Or, if the question was answered, please mark this case as solved.  


    Have a good day!