cancel
Showing results for 
Search instead for 
Did you mean: 

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

Contributor

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

Hi,

 

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">
<INL02072 HOUSNMBR="3333" HOUSCMNTSEQ1="7" HOUSCMNTLINE="ABC"/>
<SITEID>132132132</SITEID>
</ABC00053>
</ICOMS>'''
def parsed = new XmlParser().parseText( str )
log.info parsed.'**'*.attribute( 'HOUSNMBR' ).find()

 

Thanks,

Himanshu

2 REPLIES 2
Community Leader

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

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

 

http://groovy-lang.org/processing-xml.html

 

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.

Moderator

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

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!


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2