shubhimu
7 years agoContributor
Groovy Method to find out whether XML response has namespace in it or not
Hi,
Can anyone help me with the method to find out whether XML response has namespace in it or not. ?
Actually i want to achieve below:
If name space exist in response then i will set the name space and if it doesnt not exist then i will not set it.
I am using XMl holder for XMl parsing.
Thanks,
Himanshu
Hi,
you would use XmlSlurper to parse xml.Hi,
you would use XmlSlurper to parse xml. like below:
// xmlResponse
def rootNode = new XmlSlurper().parseText(xmlResponse)
def gpathClass = rootNode.getClass().getSuperclass()
def namespace = gpathClass.getDeclaredField("namespaceTagHints")
namespace.setAccessible(true)
def namespaceDeclaration = namespace.get(rootNode)
log.info namespaceDeclaration